Skip to content
Lattice

IProtocolAdapter

Git Source

Title: IProtocolAdapter

Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)

Sidecar interface implemented by every Lattice protocol adapter alongside IStrategy. Covers what IStrategy deliberately omits: sweeping pushed idle funds into the protocol (deploy), claiming and forwarding rewards raw (harvest), emergency exit, and pause/health introspection.

Adapters are stateless Diamond facets; all logic lives in their library + the shared AdapterBaseLib. Errors are declared here (interface-owned) per Lattice convention. Wide pragma so older-compiler consumers can import the ABI.

Functions

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 returns (uint256 deployed);

Returns

NameTypeDescription
deployeduint256The 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;

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 returns (uint256 recovered);

Returns

NameTypeDescription
recovereduint256The 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 returns (bool);

Returns

NameTypeDescription
<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 returns (uint256);

Returns

NameTypeDescription
<none>uint256

minHealthFactor

Returns the configured minimum health factor (WAD) the adapter must not breach.

function minHealthFactor() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256

rewardRecipient

Returns the address rewards are forwarded to.

function rewardRecipient() external view returns (address);

Returns

NameTypeDescription
<none>address

Events

Deployed

Emitted when idle funds are swept into the protocol.

event Deployed(address indexed asset, uint256 amount);

Parameters

NameTypeDescription
assetaddressThe underlying asset deployed.
amountuint256The amount deployed.

RewardsForwarded

Emitted when reward tokens are claimed and forwarded raw to the recipient.

event RewardsForwarded(address indexed rewardToken, address indexed recipient, uint256 amount);

Parameters

NameTypeDescription
rewardTokenaddressThe reward token forwarded.
recipientaddressThe configured reward recipient.
amountuint256The amount forwarded (post-transfer real delta).

RewardRecipientSet

Emitted when the reward recipient is set or changed.

event RewardRecipientSet(address indexed recipient);

Parameters

NameTypeDescription
recipientaddress

OperatorSet

Emitted when the authorized operator (the only caller permitted to invoke the deploy/withdraw/harvest trio) is set or changed.

event OperatorSet(address indexed operator);

Parameters

NameTypeDescription
operatoraddress

EmergencyWithdrawn

Emitted when the adapter fully exits its position in an emergency.

event EmergencyWithdrawn(address indexed asset, address indexed toVault, uint256 recovered);

Parameters

NameTypeDescription
assetaddressThe underlying asset recovered.
toVaultaddressThe vault the funds were returned to.
recovereduint256The amount returned to the vault.

Errors

ProtocolAdapterPaused

An operation requiring an active position was attempted while paused/stopped, or the external protocol reports paused/frozen.

error ProtocolAdapterPaused();

ProtocolAdapterZeroAddress

A zero address was supplied where a non-zero address is required.

error ProtocolAdapterZeroAddress();

ProtocolAdapterNothingToDeploy

deploy() was called with no idle balance to sweep.

error ProtocolAdapterNothingToDeploy();

ProtocolAdapterHealthFactorBreached

A lever/delever/deploy op would push the position below the configured minimum health factor.

error ProtocolAdapterHealthFactorBreached(uint256 resulting, uint256 floor);

Parameters

NameTypeDescription
resultinguint256The health factor (WAD) the op would produce.
flooruint256The configured minimum health factor (WAD).

ProtocolAdapterRewardForwardFailed

A reward token transfer to the recipient failed.

error ProtocolAdapterRewardForwardFailed(address rewardToken);

Parameters

NameTypeDescription
rewardTokenaddress

ProtocolAdapterUnauthorized

Caller is not authorized for this operation.

error ProtocolAdapterUnauthorized(address caller);

Parameters

NameTypeDescription
calleraddress

ProtocolAdapterInvalidRecipient

withdraw was called with a recipient other than the adapter's stored vault.

The recipient of a recall is pinned to the vault the adapter was initialized with, so an attacker who somehow reaches withdraw can never redirect the position to themselves.

error ProtocolAdapterInvalidRecipient(address to);

Parameters

NameTypeDescription
toaddress

ProtocolAdapterInvalidOraclePrice

The protocol's price oracle returned a non-positive (zero) asset price, which would make a valuation divide-by-zero or mis-state NAV. The valuation reverts rather than report a bogus figure.

error ProtocolAdapterInvalidOraclePrice();