AaveV3Adapter
Inherits: IStrategy, IProtocolAdapter, IAdapterOperator, IAaveV3Adapter
Title: AaveV3Adapter
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Aave V3 (https://github.com/aave-dao/aave-v3-origin)
Diamond facet adapting an Aave v3 supply (+ optional leverage) position into a Lattice
vault strategy. Implements IStrategy (funds routing), IProtocolAdapter (sidecar),
and IAaveV3Adapter (Aave config). All logic lives in AaveV3AdapterLib.
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 |
addressesProvider
Returns the Aave PoolAddressesProvider this adapter resolves the Pool from.
function addressesProvider() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
aToken
Returns the live aToken for the configured asset (resolved via the provider).
function aToken() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
vault
Returns the vault this adapter returns withdrawn funds to.
function vault() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
eModeCategory
Returns the current eMode category id set on the Pool for this adapter.
function eModeCategory() external view virtual override returns (uint8);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint8 |
rewardsController
Returns the configured Aave rewards controller (address(0) if unset).
function rewardsController() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
setEMode
Sets the Aave eMode category (admin only). Used to enable correlated-asset looping.
function setEMode(uint8 categoryId) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| categoryId | uint8 |
setMinHealthFactor
Sets the minimum health-factor floor in WAD (admin only). Must be >= 1e18.
function setMinHealthFactor(uint256 minHealthFactorWad) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| minHealthFactorWad | uint256 |
setRewardRecipient
Sets the reward recipient (admin only).
function setRewardRecipient(address recipient) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| recipient | address |
setRewardsController
Sets the Aave rewards controller (admin only).
function setRewardsController(address controller) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| controller | address |
lever
Borrows borrowAmount of the asset and re-supplies it, increasing leverage.
Reverts ProtocolAdapterHealthFactorBreached if the resulting HF < the floor.
function lever(uint256 borrowAmount) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| borrowAmount | uint256 |
delever
Withdraws collateralToPull of the asset from supply and repays that much debt,
decreasing leverage and restoring HF.
function delever(uint256 collateralToPull) external virtual override returns (uint256 repaid);Parameters
| Name | Type | Description |
|---|---|---|
| collateralToPull | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| repaid | uint256 | The amount of debt repaid. |
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 AaveV3Adapter methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
aToken() 0xa0c1f15e
addressesProvider() 0xc72c4d10
asset() 0x38d52e0f
delever(uint256) 0xcf60112b
deploy() 0x775c300c
eModeCategory() 0xa6e40bec
emergencyWithdraw() 0xdb2e21bc
harvest() 0x4641257d
healthFactor() 0x22841f01
isPaused() 0xb187bd26
lever(uint256) 0x9dcc380a
minHealthFactor() 0xe1b4264c
operator() 0x570ca735
reentrancyGuardEntered() 0xd2c725e0
rewardRecipient() 0x17f33340
rewardsController() 0x6bb65f53
setEMode(uint8) 0xb94e11c6
setMinHealthFactor(uint256) 0x01b08d58
setOperator(address) 0xb3ab15fb
setRewardRecipient(address) 0xe521136f
setRewardsController(address) 0xbee36bb3
totalAssetsManaged() 0x613c822b
vault() 0xfbfa77cf
withdraw(uint256,address) 0x00f714ce
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |