# v1.0 Pair

The v1.0Pair contracts are responsible for all pair logic including: liquidity provision, swapping, and rebalancing the pair.

The v1.0Pair 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[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#events) <a href="#events" id="events"></a>

#### Mint[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#mint) <a href="#mint" id="mint"></a>

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

Emitted each time liquidity tokens are created via mint.

#### Burn[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#burn) <a href="#burn" id="burn"></a>

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

Emitted each time liquidity tokens are destroyed via burn.

#### Swap[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#swap) <a href="#swap" id="swap"></a>

```
event Swap(
  address indexed sender,
  uint amount0In,
  uint amount1In,
  uint amount0Out,
  uint amount1Out,
  address indexed to
);
```

Emitted each time a swap occurs via swap.

#### Sync[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#sync) <a href="#sync" id="sync"></a>

```
event Sync(uint112 reserve0, uint112 reserve1);
```

Emitted each time reserves are updated via mint, burn, swap, or sync.

### Read-Only Functions[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#read-only-functions) <a href="#read-only-functions" id="read-only-functions"></a>

#### MINIMUM\_LIQUIDITY[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#minimum_liquidity) <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

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[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#factory) <a href="#factory" id="factory"></a>

```
function factory() external view returns (address);
```

Returns the factory address.

#### token0[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#token0) <a href="#token0" id="token0"></a>

```
function token0() external view returns (address);
```

Returns the address of the pair token with the lower sort order.

#### token1[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#token1) <a href="#token1" id="token1"></a>

```
function token1() external view returns (address);
```

Returns the address of the pair token with the higher sort order.

#### getReserves[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#getreserves) <a href="#getreserves" id="getreserves"></a>

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

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[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#price0cumulativelast) <a href="#price0cumulativelast" id="price0cumulativelast"></a>

```
function price0CumulativeLast() external view returns (uint);
```

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[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#price1cumulativelast) <a href="#price1cumulativelast" id="price1cumulativelast"></a>

```
function price1CumulativeLast() external view returns (uint);
```

Returns the sum of the token's price for every second in the entire history of the contract.

#### kLast[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#klast) <a href="#klast" id="klast"></a>

```
function kLast() external view returns (uint);
```

Returns the product of the reserves as of the most recent liquidity event.

### State-Changing Functions[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#state-changing-functions) <a href="#state-changing-functions" id="state-changing-functions"></a>

#### mint[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#mint-1) <a href="#mint-1" id="mint-1"></a>

```
function mint(address to) external returns (uint liquidity);
```

Creates pool tokens.

* Emits mint, Transfer

**Parameters**[**​**](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#parameters)

| Name | Type    | Description                            |
| ---- | ------- | -------------------------------------- |
| `to` | address | address of the receiver of pool tokens |

**Returns**[**​**](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#returns)

| Name        | Type | Description                        |
| ----------- | ---- | ---------------------------------- |
| `liquidity` | uint | amount of liquidity tokens created |

#### burn[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#burn-1) <a href="#burn-1" id="burn-1"></a>

```
function burn(address to) external returns (uint amount0, uint amount1);
```

Destroys pool tokens.

* Emits burn, Transfer

**Parameters**[**​**](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#parameters-1)

| Name | Type    | Description                                  |
| ---- | ------- | -------------------------------------------- |
| `to` | address | address of the receiver of token0 and token1 |

**Returns**[**​**](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#returns-1)

| Name      | Type | Description                         |
| --------- | ---- | ----------------------------------- |
| `amount0` | uint | amount of token0 returned from burn |
| `amount1` | uint | amount of token1 returned from burn |

#### swap[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#swap-1) <a href="#swap-1" id="swap-1"></a>

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

Swaps tokens. For regular swaps, `data.length` must be `0`.

* Emits swap
* Either amount0Out or amount1Out will be 0 on calls depending on what the swap is from and to.

**Parameters**[**​**](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#parameters-2)

| Name         | Type    | Description                                  |
| ------------ | ------- | -------------------------------------------- |
| `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[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#skim) <a href="#skim" id="skim"></a>

```
function skim(address to) external;
```

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**[**​**](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#parameters-3)

| Name | Type    | Description               |
| ---- | ------- | ------------------------- |
| `to` | address | address to skim tokens to |

#### sync[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#sync-1) <a href="#sync-1" id="sync-1"></a>

```
function sync() external;
```

Exists to set the the reserve of the contract to the current balances.

* Used as recovery mechanism in the case that a token asynchronously deflates the balance of a pair.

### Interface[​](https://docs.sushi.com/docs/Products/Classic%20AMM/Contracts/V2Pair#interface) <a href="#interface" id="interface"></a>

```
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```

```
pragma solidity >=0.5.0;

interface IUniswapV2ERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```
