Skip to main content

V3FeeAdapter

Git Source

Inherits: IV3FeeAdapter, Owned

A contract that allows the setting and collecting of protocol fees per pool, and adding new fee tiers to the Uniswap V3 Factory.

This contract is ownable. The owner can set the merkle root for proving protocol fee amounts per pool, set new fee tiers on Uniswap V3, and change the owner of this contract. Note that this contract will be the set owner on the Uniswap V3 Factory.

Note: security-contact: security@uniswap.org

State Variables​

FACTORY​

IUniswapV3Factory public immutable FACTORY

TOKEN_JAR​

address public immutable TOKEN_JAR

merkleRoot​

bytes32 public merkleRoot

feeSetter​

address public feeSetter

defaultFees​

Returns the default fee value for a given fee tier.

mapping(uint24 feeTier => uint8 defaultFeeValue) public defaultFees

feeTiers​

Returns four enabled fee tiers: 100, 500, 3000, 10000. May return more if more are enabled.

uint24[] public feeTiers

Functions​

onlyFeeSetter​

Ensures only the fee setter can call the setMerkleRoot and setDefaultFeeByFeeTier functions

modifier onlyFeeSetter() ;

constructor​

At construction, the fee setter defaults to 0 and its on the owner to set.

constructor(address _factory, address _tokenJar) Owned(msg.sender);

storeFeeTier​

Stores a fee tier.

Must be a fee tier that exists on the Uniswap V3 Factory.

function storeFeeTier(uint24 feeTier) public;

Parameters

NameTypeDescription
feeTieruint24The fee tier to store.

enableFeeAmount​

Enables a new fee tier on the Uniswap V3 Factory.

Only callable by owner. Also updates the feeTiers array.

function enableFeeAmount(uint24 fee, int24 tickSpacing) external onlyOwner;

Parameters

NameTypeDescription
feeuint24
tickSpacingint24The corresponding tick spacing for the new fee tier.

setFactoryOwner​

function setFactoryOwner(address newOwner) external onlyOwner;

collect​

Collects protocol fees from the specified pools to the designated TOKEN_JAR

function collect(CollectParams[] calldata collectParams)
external
returns (Collected[] memory amountsCollected);

Parameters

NameTypeDescription
collectParamsCollectParams[]Array of collection parameters for each pool.

Returns

NameTypeDescription
amountsCollectedCollected[]Array of collected amounts for each pool.

setMerkleRoot​

Sets the merkle root used for designating which pools have the fee enabled.

Only callable by feeSetter

function setMerkleRoot(bytes32 _merkleRoot) external onlyFeeSetter;

Parameters

NameTypeDescription
_merkleRootbytes32The new merkle root to set.

setDefaultFeeByFeeTier​

Sets the default fee value for a specific fee tier.

function setDefaultFeeByFeeTier(uint24 feeTier, uint8 defaultFeeValue) external onlyFeeSetter;

Parameters

NameTypeDescription
feeTieruint24The fee tier, expressed in pips, to set the default fee for.
defaultFeeValueuint8The default fee value to set, expressed as the denominator on the inclusive interval [4, 10]. The fee value is packed (token1Fee << 4 | token0Fee)

setFeeSetter​

Sets a new fee setter address.

function setFeeSetter(address newFeeSetter) external onlyOwner;

Parameters

NameTypeDescription
newFeeSetteraddressThe new address authorized to set fees and merkle roots.

triggerFeeUpdate​

Triggers a fee update for a single pool with merkle proof verification.

function triggerFeeUpdate(address pool, bytes32[] calldata proof) external;

Parameters

NameTypeDescription
pooladdressThe pool address to update the fee for.
proofbytes32[]

triggerFeeUpdate​

Triggers a fee update for a single pool with merkle proof verification.

function triggerFeeUpdate(address token0, address token1, bytes32[] calldata proof) external;

Parameters

NameTypeDescription
token0address
token1address
proofbytes32[]

batchTriggerFeeUpdate​

Triggers fee updates for multiple pairs of tokens with batch merkle proof verification.

Assumes that token0 < token1 in the token pair.

function batchTriggerFeeUpdate(
Pair[] calldata pairs,
bytes32[] calldata proof,
bool[] calldata proofFlags
) external;

Parameters

NameTypeDescription
pairsPair[]The pair of two tokens. There may be multiple pools initialized from the same pair.
proofbytes32[]The merkle proof corresponding to the set merkle root.
proofFlagsbool[]The flags for the merkle proof verification.

_setProtocolFeesForPair​

function _setProtocolFeesForPair(address token0, address token1) internal;

_setProtocolFee​

function _setProtocolFee(address pool, uint24 feeTier) internal;

_doubleHash​

function _doubleHash(address token0, address token1) internal pure returns (bytes32 poolHash);

_feeTierExists​

function _feeTierExists(uint24 feeTier) internal view returns (bool);