Pair
https://github.com/Into-the-Fathom/fathom-swap-smart-contracts/blob/master/contracts/core/UniswapV2Pair.sol
The UniswapV2Pair
contract is a core component of the Uniswap decentralized exchange. It facilitates liquidity pools between two ERC-20 tokens, enabling token swaps and liquidity management. The contract allows users to add and remove liquidity, swap tokens, and ensure reserves are synchronized with balances. It also supports permits for approvals via signatures and enforces the constant product formula for swaps. The contract emits events to track key actions such as minting, burning, and swapping of tokens.
State Variables
factory
Type:
address
Description: The address of the factory contract that created this pair.
token0
Type:
address
Description: The address of the first token in the pair.
token1
Type:
address
Description: The address of the second token in the pair.
reserve0
Type:
uint112
Description: The reserve of token0.
reserve1
Type:
uint112
Description: The reserve of token1.
blockTimestampLast
Type:
uint32
Description: The timestamp of the last block when the reserves were updated.
price0CumulativeLast
Type:
uint
Description: Cumulative price of token0.
price1CumulativeLast
Type:
uint
Description: Cumulative price of token1.
kLast
Type:
uint
Description: The product of the reserves, as of the last liquidity event.
unlocked
Type:
uint
Description: Mutex variable to prevent reentrancy.
Set Functions
mint
Parameters:
address to
Returns:
uint liquidity
: The amount of liquidity minted.
Description: Mints new liquidity tokens and sends them to the specified address. Updates reserves and handles fees.
burn
Parameters:
address to
Returns:
uint amount0
: The amount of token0 burned.uint amount1
: The amount of token1 burned.
Description: Burns liquidity tokens and sends the underlying assets to the specified address. Updates reserves and handles fees.
swap
Parameters:
uint amount0Out
uint amount1Out
address to
bytes calldata data
Returns: None
Description: Swaps tokens and sends the output to the specified address. Allows for callbacks to execute additional logic.
skim
Parameters:
address to
Returns: None
Description: Transfers any token balances to the specified address, bringing the token balances in line with the reserves.
sync
Parameters: None
Returns: None
Description: Forces reserves to match the token balances in the contract.
Read Functions
name
Parameters: None
Returns:
string
: The name of the token.
Description: Returns the name of the token.
symbol
Parameters: None
Returns:
string
: The symbol of the token.
Description: Returns the symbol of the token.
decimals
Parameters: None
Returns:
uint8
: The number of decimals the token uses.
Description: Returns the number of decimals the token uses.
totalSupply
Parameters: None
Returns:
uint
: The total supply of the token.
Description: Returns the total supply of the token.
balanceOf
Parameters:
address owner
Returns:
uint
: The balance of the specified address.
Description: Returns the token balance of the specified address.
allowance
Parameters:
address owner
address spender
Returns:
uint
: The remaining number of tokens that the spender is allowed to spend.
Description: Returns the remaining number of tokens that the spender is allowed to spend on behalf of the owner.
DOMAIN_SEPARATOR
Parameters: None
Returns:
bytes32
: The EIP-712 domain separator.
Description: Returns the EIP-712 domain separator.
PERMIT_TYPEHASH
Parameters: None
Returns:
bytes32
: The permit typehash.
Description: Returns the permit typehash.
nonces
Parameters:
address owner
Returns:
uint
: The current nonce for the specified address.
Description: Returns the current nonce for the specified address.
MINIMUM_LIQUIDITY
Parameters: None
Returns:
uint
: The minimum liquidity amount.
Description: Returns the minimum liquidity amount.
getReserves
Parameters: None
Returns:
uint112 reserve0
uint112 reserve1
uint32 blockTimestampLast
Description: Returns the current reserves of the pair and the timestamp of the last block.
price0CumulativeLast
Parameters: None
Returns:
uint
: The last cumulative price of token0.
Description: Returns the last cumulative price of token0.
price1CumulativeLast
Parameters: None
Returns:
uint
: The last cumulative price of token1.
Description: Returns the last cumulative price of token1.
Events
Approval
Parameters:
address indexed owner
: The address of the token owner.address indexed spender
: The address of the spender.uint value
: The amount of tokens approved for spending.
Description: Emitted when the allowance of a
spender
for anowner
is set by a call toapprove
.value
is the new allowance.
Transfer
Parameters:
address indexed from
: The address from which the tokens are transferred.address indexed to
: The address to which the tokens are transferred.uint value
: The amount of tokens transferred.
Description: Emitted when
value
tokens are moved from one account (from
) to another (to
).
Mint
Parameters:
address indexed sender
: The address initiating the minting.uint amount0
: The amount of token0 added.uint amount1
: The amount of token1 added.
Description: Emitted when liquidity is minted for the pair.
Burn
Parameters:
address indexed sender
: The address initiating the burning.uint amount0
: The amount of token0 removed.uint amount1
: The amount of token1 removed.address indexed to
: The address to which the burned tokens are sent.
Description: Emitted when liquidity is burned for the pair.
Swap
Parameters:
address indexed sender
: The address initiating the swap.uint amount0In
: The amount of token0 input.uint amount1In
: The amount of token1 input.uint amount0Out
: The amount of token0 output.uint amount1Out
: The amount of token1 output.address indexed to
: The address to which the output tokens are sent.
Description: Emitted when a swap is executed.
Sync
Parameters:
uint112 reserve0
: The new reserve of token0.uint112 reserve1
: The new reserve of token1.
Description: Emitted when the reserves of the pair are synchronized.
Last updated