Skip to content
Lattice

UniswapV3Adapter

Git Source

Inherits: IStrategy, IProtocolAdapter, IAdapterOperator, IUniswapV3Adapter

Title: UniswapV3Adapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Uniswap V3 (https://github.com/Uniswap/v3-periphery)

Diamond facet adapting a full-range Uniswap V3 LP position into a Lattice vault strategy. Implements IStrategy (funds routing), IProtocolAdapter (sidecar), and IUniswapV3Adapter (Uniswap config). This is a CUSTOM adapter: a v3 LP is a two-token, NFT-wrapped concentrated-liquidity position that does not fit the single-asset IStrategy surface cleanly. Compromises (all documented in UniswapV3AdapterLib): full-range only (no active range management), swap-free (the keeper funds both tokens), asset == token0, and NAV counts token0 only (idle token0 plus the position's token0 leg), valued from the pool TWAP (observe), never slot0 spot. A deploy, priced by the pool at spot, is refused when it would step that NAV by more than slippageBps of the token0 it consumes. A recall pays idle token0 only; the admin's emergencyWithdraw is the sole exit from the position. All logic lives in UniswapV3AdapterLib.

Provenance: Uniswap V3 core (https://github.com/Uniswap/v3-core) + periphery NonfungiblePositionManager (https://github.com/Uniswap/v3-periphery). The facet implements onERC721Received so the NFPM can safe-mint the position NFT to it.

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

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

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

NameTypeDescription
amountuint256Amount of underlying asset to withdraw.
toaddressRecipient address (typically the vault).

Returns

NameTypeDescription
withdrawnuint256Actual 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

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 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

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

Returns

NameTypeDescription
<none>uint256

minHealthFactor

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

function minHealthFactor() external view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256

rewardRecipient

Returns the address rewards are forwarded to.

function rewardRecipient() external view virtual override returns (address);

Returns

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

NameTypeDescription
operator_addressThe new operator (typically the StrategyManager diamond).

operator

Returns the authorized operator (zero until wired).

function operator() external view virtual override returns (address);

Returns

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

NameTypeDescription
<none>bool

positionManager

Returns the Uniswap V3 NonfungiblePositionManager.

function positionManager() external view virtual override returns (address);

Returns

NameTypeDescription
<none>address

pool

Returns the Uniswap V3 pool the adapter LPs into.

function pool() external view virtual override returns (address);

Returns

NameTypeDescription
<none>address

token0

Returns the pool's token0 (== the adapter's asset, the vault-facing accounting token).

function token0() external view virtual override returns (address);

Returns

NameTypeDescription
<none>address

token1

Returns the pool's token1 (supplied by the keeper, never swapped by the adapter).

function token1() external view virtual override returns (address);

Returns

NameTypeDescription
<none>address

fee

Returns the pool fee tier (hundredths of a bip).

function fee() external view virtual override returns (uint24);

Returns

NameTypeDescription
<none>uint24

tokenId

Returns the current position NFT id (0 == no position minted yet).

function tokenId() external view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256

vault

Returns the Lattice vault funds are returned to on emergency exit.

function vault() external view virtual override returns (address);

Returns

NameTypeDescription
<none>address

twapWindow

Returns the TWAP observation window (seconds) used for valuation.

function twapWindow() external view virtual override returns (uint32);

Returns

NameTypeDescription
<none>uint32

slippageBps

Returns the configured slippage tolerance in basis points.

function slippageBps() external view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256

setTwapWindow

Sets the TWAP observation window in seconds (admin only). Must be non-zero.

function setTwapWindow(uint32 twapWindow_) external virtual override;

Parameters

NameTypeDescription
twapWindow_uint32

setSlippageBps

Sets the slippage tolerance in basis points (admin only).

function setSlippageBps(uint256 slippageBps_) external virtual override;

Parameters

NameTypeDescription
slippageBps_uint256

setRewardRecipient

Sets the reward recipient (admin only).

function setRewardRecipient(address recipient) external virtual override;

Parameters

NameTypeDescription
recipientaddress

onERC721Received

Accepts the Uniswap V3 position NFT safe-minted by the NonfungiblePositionManager.

Returns the IERC721Receiver.onERC721Received selector so _safeMint succeeds. The adapter is the position custodian; it never expects any other NFT, but this handler is intentionally permissive (returns the magic value unconditionally) so the mint path on the real NFPM cannot revert.

function onERC721Received(address, address, uint256, bytes calldata) external virtual returns (bytes4);

Parameters

NameTypeDescription
_address
_address
_uint256
_bytes

Returns

NameTypeDescription
<none>bytes4

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 UniswapV3Adapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: asset() 0x38d52e0f deploy() 0x775c300c emergencyWithdraw() 0xdb2e21bc fee() 0xddca3f43 harvest() 0x4641257d healthFactor() 0x22841f01 isPaused() 0xb187bd26 minHealthFactor() 0xe1b4264c onERC721Received(address,address,uint256,bytes) 0x150b7a02 operator() 0x570ca735 pool() 0x16f0115b positionManager() 0x791b98bc reentrancyGuardEntered() 0xd2c725e0 rewardRecipient() 0x17f33340 setOperator(address) 0xb3ab15fb setRewardRecipient(address) 0xe521136f setSlippageBps(uint256) 0x1a3ce4e6 setTwapWindow(uint32) 0x5f553545 slippageBps() 0x578c71d9 token0() 0x0dfe1681 token1() 0xd21220a7 tokenId() 0x17d70f7c totalAssetsManaged() 0x613c822b twapWindow() 0x8107e133 vault() 0xfbfa77cf withdraw(uint256,address) 0x00f714ce

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes