Skip to content
Lattice

CompoundV3AdapterLib

Git Source

Title: CompoundV3AdapterLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Compound V3 (https://github.com/compound-finance/comet)

Logic for the Compound v3 supply adapter. 1:1 base-asset accounting (no oracle). Reentrancy-gated, pause/emergency-aware, shortfall-honest. Rewards forwarded raw.

Functions

compoundV3AdapterStorage

function compoundV3AdapterStorage() internal pure returns (CompoundV3AdapterStorage storage $);

Returns

NameTypeDescription
$CompoundV3AdapterStorage

__CompoundV3Adapter_init

function __CompoundV3Adapter_init(address comet_, address asset_, address vault_, address recipient_) internal;

Parameters

NameTypeDescription
comet_address
asset_address
vault_address
recipient_address

registerInterface

function registerInterface() internal;

asset

function asset() internal view returns (address);

Returns

NameTypeDescription
<none>address

vault

function vault() internal view returns (address);

Returns

NameTypeDescription
<none>address

comet

function comet() internal view returns (address);

Returns

NameTypeDescription
<none>address

cometRewards

function cometRewards() internal view returns (address);

Returns

NameTypeDescription
<none>address

rewardRecipient

function rewardRecipient() internal view returns (address);

Returns

NameTypeDescription
<none>address

operator

function operator() internal view returns (address);

Returns

NameTypeDescription
<none>address

_checkOperator

Reverts ProtocolAdapterUnauthorized unless the caller is the wired operator. Placed at the very top of deploy/withdraw/harvest — BEFORE the reentrancy guard — so an unauthorized call never leaves the guard latched. Zero operator ⇒ always reverts.

function _checkOperator() private view;

minHealthFactor

function minHealthFactor() internal pure returns (uint256);

Returns

NameTypeDescription
<none>uint256

healthFactor

function healthFactor() internal pure returns (uint256);

Returns

NameTypeDescription
<none>uint256

isPaused

function isPaused() internal view returns (bool);

Returns

NameTypeDescription
<none>bool

totalAssetsManaged

1:1 base-asset accounting. Comet's balanceOf is present-value and already reflects accrued interest, so no pre-accrue is needed and this stays view (matching the IStrategy.totalAssetsManaged() view signature). No oracle.

Idle leg (NAV-gap fix): adds the adapter's idle base-asset balance to the Comet position. IVaultCore.allocateToStrategy pushes funds here with a bare transfer that does NOT supply to Comet, so undeployed funds sit idle until deploy(). Counting that idle keeps the vault's share price flat across the allocate→deploy window. No double-count: the idle is in neither the vault's idle nor the Comet balance, and after deploy() idle→~0 while the Comet balance rises by the same amount, so the sum is invariant across deploy.

function totalAssetsManaged() internal view returns (uint256);

Returns

NameTypeDescription
<none>uint256

setCometRewards

function setCometRewards(address rewards) internal;

Parameters

NameTypeDescription
rewardsaddress

setRewardRecipient

function setRewardRecipient(address recipient) internal;

Parameters

NameTypeDescription
recipientaddress

setOperator

Sets the authorized operator for deploy/withdraw/harvest (admin-only). Rejects address(0) so the trio cannot be opened to an unauthenticated default.

function setOperator(address operator_) internal;

Parameters

NameTypeDescription
operator_address

deploy

function deploy() internal returns (uint256 deployed);

Returns

NameTypeDescription
deployeduint256

withdraw

Recalls up to amount of the base asset to to, spending undeployed idle before the Comet position, and returns the real amount sent.

The Comet ask is capped at the adapter's supplied balance and at the market's available cash, the base asset Comet itself holds (Comet.withdraw pays out of its own balance and reverts when that is short). During a utilisation spike the recall therefore takes what the market can pay instead of reverting the calling rebalance() (#271); with no cash it skips Comet. A delivery short of amount is an honest partial recall: the unpaid remainder is still supplied and counted, so the StrategyManager accepts it and a later rebalance finishes it.

function withdraw(uint256 amount, address to) internal returns (uint256 withdrawn);

Parameters

NameTypeDescription
amountuint256
toaddress

Returns

NameTypeDescription
withdrawnuint256

harvest

function harvest() internal;

emergencyWithdraw

function emergencyWithdraw() internal returns (uint256 recovered);

Returns

NameTypeDescription
recovereduint256