Request form
Uniswap V3
  • Uniswap
  • DEX
  • Exchange
  • Token
  • Protocol
  • Audited
Docs
Source
ChefGPT

A fully decentralized protocol for automated liquidity provision on Ethereum. V3

IUniswapV3Pool :
The pool interface is broken up into many smaller pieces
burn(int24,int24,uint128) :
Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0Fees must be collected separately via a call to #collect
collect(address,int24,int24,uint128,uint128) :
Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
feeGrowthGlobal0X128() :
This value can overflow the uint256
feeGrowthGlobal1X128() :
This value can overflow the uint256
flash(address,uint256,uint256,bytes) :
The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallbackCan be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling with 0 amount{0,1} and sending the donation amount(s) from the callback
increaseObservationCardinalityNext(uint16) :
This method is no-op if the pool already has an observationCardinalityNext greater than or equal to the input observationCardinalityNext.
initialize(uint160) :
Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
liquidity() :
This value has no relationship to the total liquidity across all ticks
maxLiquidityPerTick() :
This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
mint(address,int24,int24,uint128,bytes) :
The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends on tickLower, tickUpper, the amount of liquidity, and the current price.
observations(uint256) :
You most likely want to use #observe() instead of this method to get an observation as of some amount of time ago, rather than at a specific index in the array.
observe(uint32[]) :
To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, you must call it with secondsAgos = [3600, 0].The time weighted average tick represents the geometric time weighted average price of the pool, in log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
protocolFees() :
Protocol fees will never exceed uint128 max in either token
snapshotCumulativesInside(int24,int24) :
Snapshots must only be compared to other snapshots, taken over a period for which a position existed. I.e., snapshots cannot be compared if a position is not held for the entire period between when the first snapshot is taken and the second snapshot is taken.
swap(address,bool,int256,uint160,bytes) :
The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
tickSpacing() :
Ticks can only be used at multiples of this value, minimum of 1 and always positive e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... This value is an int24 to avoid casting even though it is always positive.
IUniswapV3PoolDeployer :
This is used to avoid having constructor arguments in the pool contract, which results in the init code hash of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain
parameters() :
Called by the pool constructor to fetch the parameters of the pool Returns factory The factory address Returns token0 The first token of the pool by address sort order Returns token1 The second token of the pool by address sort order Returns fee The fee collected upon every swap in the pool, denominated in hundredths of a bip Returns tickSpacing The minimum number of ticks between initialized ticks
BitMath :
This library provides functionality for computing bit properties of an unsigned integer
FixedPoint96 :
Used in SqrtPriceMath.sol
FullMath :
Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
Oracle :
Instances of stored oracle data, "observations", are collected in the oracle array Every pool is initialized with an oracle array length of 1. Anyone can pay the SSTOREs to increase the maximum length of the oracle array. New slots will be added when the array is fully populated. Observations are overwritten when the full length of the oracle array is populated. The most recent observation is available, independent of the length of the oracle array, by passing 0 to observe()
Position :
Positions store additional state for tracking fees owed to the position
TickBitmap :
The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.
NoDelegateCall.sol
UniswapV3Factory.sol
UniswapV3Pool.sol
UniswapV3PoolDeployer.sol
IERC20Minimal.sol
IUniswapV3Factory.sol
IUniswapV3Pool.sol
IUniswapV3PoolDeployer.sol
IUniswapV3FlashCallback.sol
IUniswapV3MintCallback.sol
IUniswapV3SwapCallback.sol
IUniswapV3PoolActions.sol
IUniswapV3PoolDerivedState.sol
IUniswapV3PoolEvents.sol
IUniswapV3PoolImmutables.sol
IUniswapV3PoolOwnerActions.sol
IUniswapV3PoolState.sol
BitMath.sol
FixedPoint128.sol
FixedPoint96.sol
FullMath.sol
LiquidityMath.sol
LowGasSafeMath.sol
Oracle.sol
Position.sol
SafeCast.sol
SqrtPriceMath.sol
SwapMath.sol
Tick.sol
TickBitmap.sol
TickMath.sol
TransferHelper.sol
UnsafeMath.sol
BitMathEchidnaTest.sol
BitMathTest.sol
FullMathEchidnaTest.sol
FullMathTest.sol
LiquidityMathTest.sol
LowGasSafeMathEchidnaTest.sol
MockTimeUniswapV3Pool.sol
MockTimeUniswapV3PoolDeployer.sol
NoDelegateCallTest.sol
OracleEchidnaTest.sol
OracleTest.sol
SqrtPriceMathEchidnaTest.sol
SqrtPriceMathTest.sol
SwapMathEchidnaTest.sol
SwapMathTest.sol
TestERC20.sol
TestUniswapV3Callee.sol
TestUniswapV3ReentrantCallee.sol
TestUniswapV3Router.sol
TestUniswapV3SwapPay.sol
TickBitmapEchidnaTest.sol
TickBitmapTest.sol
TickEchidnaTest.sol
TickMathEchidnaTest.sol
TickMathTest.sol
TickOverflowSafetyEchidnaTest.sol
TickTest.sol
UniswapV3PoolSwapTest.sol
UnsafeMathEchidnaTest.sol

TVL

$3.14B

581 downloads

Chains

Authors

Uniswap V3
  • Uniswap
  • DEX
  • Exchange
  • Token
  • Protocol
  • Audited
Info
Docs
Source
ChefGPT
Expand
Share

Get Cookin'

581 downloads

Chains

Authors

Uniswap V3

Lint Tests Fuzz Testing Mythx npm version

This repository contains the core smart contracts for the Uniswap V3 Protocol. For higher level contracts, see the uniswap-v3-periphery repository.

Bug bounty

This repository is subject to the Uniswap V3 bug bounty program, per the terms defined here.

Local deployment

In order to deploy this code to a local testnet, you should install the npm package @uniswap/v3-core and import the factory bytecode located at @uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json. For example:

import {
  abi as FACTORY_ABI,
  bytecode as FACTORY_BYTECODE,
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'

// deploy the bytecode

This will ensure that you are testing against the same bytecode that is deployed to mainnet and public testnets, and all Uniswap code will correctly interoperate with your local deployment.

Using solidity interfaces

The Uniswap v3 interfaces are available for import into solidity smart contracts via the npm artifact @uniswap/v3-core, e.g.:

import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';

contract MyContract {
  IUniswapV3Pool pool;

  function doSomethingWithPool() {
    // pool.swap(...);
  }
}

Licensing

The primary license for Uniswap V3 Core is the Business Source License 1.1 (BUSL-1.1), see LICENSE. However, some files are dual licensed under GPL-2.0-or-later:

  • All files in contracts/interfaces/ may also be licensed under GPL-2.0-or-later (as indicated in their SPDX headers), see contracts/interfaces/LICENSE
  • Several files in contracts/libraries/ may also be licensed under GPL-2.0-or-later (as indicated in their SPDX headers), see contracts/libraries/LICENSE

Other Exceptions

  • contracts/libraries/FullMath.sol is licensed under MIT (as indicated in its SPDX header), see contracts/libraries/LICENSE_MIT
  • All files in contracts/test remain unlicensed (as indicated in their SPDX headers).
A fully decentralized protocol for automated liquidity provision on Ethereum. V3
IUniswapV3Pool :
The pool interface is broken up into many smaller pieces
burn(int24,int24,uint128) :
Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0Fees must be collected separately via a call to #collect
collect(address,int24,int24,uint128,uint128) :
Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
feeGrowthGlobal0X128() :
This value can overflow the uint256
feeGrowthGlobal1X128() :
This value can overflow the uint256
flash(address,uint256,uint256,bytes) :
The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallbackCan be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling with 0 amount{0,1} and sending the donation amount(s) from the callback
increaseObservationCardinalityNext(uint16) :
This method is no-op if the pool already has an observationCardinalityNext greater than or equal to the input observationCardinalityNext.
initialize(uint160) :
Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
liquidity() :
This value has no relationship to the total liquidity across all ticks
maxLiquidityPerTick() :
This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
mint(address,int24,int24,uint128,bytes) :
The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends on tickLower, tickUpper, the amount of liquidity, and the current price.
observations(uint256) :
You most likely want to use #observe() instead of this method to get an observation as of some amount of time ago, rather than at a specific index in the array.
observe(uint32[]) :
To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, you must call it with secondsAgos = [3600, 0].The time weighted average tick represents the geometric time weighted average price of the pool, in log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
protocolFees() :
Protocol fees will never exceed uint128 max in either token
snapshotCumulativesInside(int24,int24) :
Snapshots must only be compared to other snapshots, taken over a period for which a position existed. I.e., snapshots cannot be compared if a position is not held for the entire period between when the first snapshot is taken and the second snapshot is taken.
swap(address,bool,int256,uint160,bytes) :
The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
tickSpacing() :
Ticks can only be used at multiples of this value, minimum of 1 and always positive e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... This value is an int24 to avoid casting even though it is always positive.
IUniswapV3PoolDeployer :
This is used to avoid having constructor arguments in the pool contract, which results in the init code hash of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain
parameters() :
Called by the pool constructor to fetch the parameters of the pool Returns factory The factory address Returns token0 The first token of the pool by address sort order Returns token1 The second token of the pool by address sort order Returns fee The fee collected upon every swap in the pool, denominated in hundredths of a bip Returns tickSpacing The minimum number of ticks between initialized ticks
BitMath :
This library provides functionality for computing bit properties of an unsigned integer
FixedPoint96 :
Used in SqrtPriceMath.sol
FullMath :
Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
Oracle :
Instances of stored oracle data, "observations", are collected in the oracle array Every pool is initialized with an oracle array length of 1. Anyone can pay the SSTOREs to increase the maximum length of the oracle array. New slots will be added when the array is fully populated. Observations are overwritten when the full length of the oracle array is populated. The most recent observation is available, independent of the length of the oracle array, by passing 0 to observe()
Position :
Positions store additional state for tracking fees owed to the position
TickBitmap :
The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.
NoDelegateCall.sol
UniswapV3Factory.sol
UniswapV3Pool.sol
UniswapV3PoolDeployer.sol
IERC20Minimal.sol
IUniswapV3Factory.sol
IUniswapV3Pool.sol
IUniswapV3PoolDeployer.sol
IUniswapV3FlashCallback.sol
IUniswapV3MintCallback.sol
IUniswapV3SwapCallback.sol
IUniswapV3PoolActions.sol
IUniswapV3PoolDerivedState.sol
IUniswapV3PoolEvents.sol
IUniswapV3PoolImmutables.sol
IUniswapV3PoolOwnerActions.sol
IUniswapV3PoolState.sol
BitMath.sol
FixedPoint128.sol
FixedPoint96.sol
FullMath.sol
LiquidityMath.sol
LowGasSafeMath.sol
Oracle.sol
Position.sol
SafeCast.sol
SqrtPriceMath.sol
SwapMath.sol
Tick.sol
TickBitmap.sol
TickMath.sol
TransferHelper.sol
UnsafeMath.sol
BitMathEchidnaTest.sol
BitMathTest.sol
FullMathEchidnaTest.sol
FullMathTest.sol
LiquidityMathTest.sol
LowGasSafeMathEchidnaTest.sol
MockTimeUniswapV3Pool.sol
MockTimeUniswapV3PoolDeployer.sol
NoDelegateCallTest.sol
OracleEchidnaTest.sol
OracleTest.sol
SqrtPriceMathEchidnaTest.sol
SqrtPriceMathTest.sol
SwapMathEchidnaTest.sol
SwapMathTest.sol
TestERC20.sol
TestUniswapV3Callee.sol
TestUniswapV3ReentrantCallee.sol
TestUniswapV3Router.sol
TestUniswapV3SwapPay.sol
TickBitmapEchidnaTest.sol
TickBitmapTest.sol
TickEchidnaTest.sol
TickMathEchidnaTest.sol
TickMathTest.sol
TickOverflowSafetyEchidnaTest.sol
TickTest.sol
UniswapV3PoolSwapTest.sol
UnsafeMathEchidnaTest.sol