CompoundV3Adapter
Inherits: IStrategy, IProtocolAdapter, IAdapterOperator, ICompoundV3Adapter
Title: CompoundV3Adapter
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Compound V3 (https://github.com/compound-finance/comet)
Diamond facet adapting a Compound v3 (Comet) base-asset supply position into a Lattice
vault strategy. Implements IStrategy (funds routing), IProtocolAdapter (sidecar),
and ICompoundV3Adapter (Comet config). Supply-only (no leverage); 1:1 base accounting,
no oracle. All logic lives in CompoundV3AdapterLib.
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 |
comet
Returns the Comet market this adapter supplies to.
function comet() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
vault
Returns the vault funds are returned to.
function vault() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
cometRewards
Returns the Comet rewards controller.
function cometRewards() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
setCometRewards
Sets the Comet rewards controller (admin only).
function setCometRewards(address rewards) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| rewards | 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 CompoundV3Adapter methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
asset() 0x38d52e0f
comet() 0xba3e9c12
cometRewards() 0x32315972
deploy() 0x775c300c
emergencyWithdraw() 0xdb2e21bc
harvest() 0x4641257d
healthFactor() 0x22841f01
isPaused() 0xb187bd26
minHealthFactor() 0xe1b4264c
operator() 0x570ca735
reentrancyGuardEntered() 0xd2c725e0
rewardRecipient() 0x17f33340
setCometRewards(address) 0x36cbb3c3
setOperator(address) 0xb3ab15fb
setRewardRecipient(address) 0xe521136f
totalAssetsManaged() 0x613c822b
vault() 0xfbfa77cf
withdraw(uint256,address) 0x00f714ce
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |