V2Pair
The V2Pair contracts are responsible for all pair logic including: liquidity provision, swapping, and rebalancing the pair.
The V2Pair contract inherits ERC20 functionality, so all usual ERC20 can be used with pair tokens.
This documentation covers pool specific functionality, where the full contract can be found here.
Eventsβ
Mintβ
event Mint(address indexed sender, uint amount0, uint amount1);Emitted each time liquidity tokens are created via mint
Burnβ
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);Emitted each time liquidity tokens are destroyed via burn.
Swapβ
Emitted each time a swap occurs via swap.
Syncβ
Emitted each time reserves are updated via mint, burn, swap, or sync.
Read-Only Functionsβ
MINIMUM_LIQUIDITYβ
Returns 1000 for all pairs.
To ameliorate rounding errors and increase the theoretical minimum tick size for liquidity provision, pairs burn the first MINIMUM_LIQUIDITY pool tokens.
Happens automatically during the first liquidity provision.
factoryβ
Returns the factory address.
token0β
Returns the address of the pair token with the lower sort order.
token1β
Returns the address of the pair token with the higher sort order.
getReservesβ
Returns the reserves of token0 and token1 used to price trades and distribute liquidity. Also returns the block.timestamp (mod 2**32) of the last block during which an interaction occurred for the pair.
price0CumulativeLastβ
Returns the sum of the token's price for every second in the entire history of the contract.
Can be used to track accurate time-weighted average prices (TWAP)s across any time interval.
The TWAP is constructed by reading the cumulative price at the beginning and at the end of the desired TWAP interval. The difference in this cumulative price can then be divided by the length of the interval to create a TWAP for that period.
price1CumulativeLastβ
Returns the sum of the token's price for every second in the entire history of the contract.
kLastβ
Returns the product of the reserves as of the most recent liquidity event.
State-Changing Functionsβ
mintβ
Creates pool tokens.
Parametersβ
to
address
address of the receiver of pool tokens
Returnsβ
liquidity
uint
amount of liquidity tokens created
burnβ
Destroys pool tokens.
Parametersβ
to
address
address of the receiver of token0 and token1
Returnsβ
amount0
uint
amount of token0 returned from burn
amount1
uint
amount of token1 returned from burn
swapβ
Swaps tokens. For regular swaps, data.length must be 0.
Either amount0Out or amount1Out will be 0 on calls depending on what the swap is from and to.
Parametersβ
amount0Out
uint
address of the receiver of pool tokens
amount1Out
uint
address of the other token in the pair
to
address
address of the receiver of out token
data
bytes
calldata data to pass forward after the swap
skimβ
Allows a user to withdraw the difference between the current balance of the pair and 2^112 - 1 to the caller, if that difference is greater than 0.
Used as a recovery mechanism in case enough tokens are sent to a pair to overflow the two uint112 storage slots for reserves, which could otherwise cause trades to fail.
Parametersβ
to
address
address to skim tokens to
syncβ
Exists to set the the reserve of the contract to the current balances.
Emits Sync.
Used as recovery mechanism in the case that a token asynchronously deflates the balance of a pair.
Interfaceβ
Last updated