# vPairFactory

## Events

#### PairCreated

```solidity
event PairCreated(
    address poolAddress,
    address factory,
    address token0,
    address token1,
    uint16 fee,
    uint16 vFee,
    uint256 maxReserveRatio
);
```

Emitted when a new pair is created in the [`createPair`](#exchangereserveaddresschanged-1) function.

#### DefaultAllowListChanged

```solidity
event DefaultAllowListChanged(address[] allowList);
```

Emitted when the default allow list changes in [`setDefaultAllowList`](#function-setdefaultallowlist) method.

#### FactoryNewPendingAdmin

```solidity
event FactoryNewPendingAdmin(address newPendingAdmin);
```

Emitted when a new pending admin is set in setPendingAdmin method.

#### FactoryNewAdmin

```solidity
event FactoryNewAdmin(address newAdmin);
```

Emitted when the factory admin is changed in acceptAdmin function.

#### FactoryNewPendingEmergencyAdmin

```solidity
event FactoryNewPendingEmergencyAdmin(address newPendingEmergencyAdmin);
```

Emitted when a new pending Emergency admin is set in `setPendingEmergencyAdmin` method.

#### FactoryNewEmergencyAdmin

```solidity
event FactoryNewEmergencyAdmin(address newEmergencyAdmin);
```

Emitted when the factory admin is changed in `acceptEmergencyAdmin` function.

#### ExchangeReserveAddressChanged

```solidity
event ExchangeReserveAddressChanged(
    address newExchangeReserve
);
```

Emitted when vExchangeReserve instance address is changed in changeAdmin function.

#### FactoryVPoolManagerChanged

```solidity
event FactoryVPoolManagerChanged(address newVPoolManager);
```

Emitted when vPoolManager address is changed in `setVPoolManagerAddress` function.

## State-Changing Functions

#### createPair

```solidity
 function createPair(
    address tokenA, 
    address tokenB
 )
 external
 returns (
    address
 );
```

Creates a new vPair instance between two to given tokens. Emits [`PairCreated`](#paircreated) event.

✏️If the pair already exist, the function fails.

Parameters:

<table><thead><tr><th width="164">Name</th><th width="162">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenA</td><td><code>address</code></td><td>First ERC-20 token in the pair</td></tr><tr><td>tokenB</td><td><code>address</code></td><td>Second ERC-20 token in the pair</td></tr></tbody></table>

#### function setPendingAdmin

```solidity
function setPendingAdmin(
      address newPendingAdmin
  ) external override onlyAdmin
```

The first step in updating the address of the admin wallet for the `vPairFactory` instance. After this method is called, [`acceptAdmin`](#function-acceotadmin) must be called to complete the process of changing the Admin

The admin wallet is the only wallet that can call the [`setExchangeReserveAddress`](#unction-changeadmin) and the [`setPendingAdmin`](#function-setpendingadmin) functions.

Emits [`FatoryNewPendingAdmin`](#factorynewpendingadmin) event

✏️Can only be called by the current Admin

#### function acceptAdmin

```solidity
function acceptAdmin() external override 
```

The second step in updating the address of the admin wallet for the VirtuSwap DEX&#x20;

The admin wallet is the only wallet that can call the [`setExchangeReserveAddress`](#unction-changeadmin) and the [`setPendingAdmin`](#function-setpendingadmin) functions.

Emits [`FactoryNewAdmin`](#factorynewadmin) event.

✏️Can only be called by the Pending Admin set by [`setPendingAdmin`](#function-setpendingadmin) method.

#### function setPendingEmergencyAdmin

```solidity
function setPendingEmergencyAdmin(
      address newPendingAdmin
  ) external override onlyAdmin
```

The first step in updating the address of the Emergency Admin wallet for VirtuSwap DEX. After this method is called, [`acceptEmergencyAdmin`](#function-acceptemergencyadmin) must be called to complete the process of changing the Emergency Admin

The Emergency Admin wallet is the only wallet that can set the ReseveRatioWarningThreshold and perform liquidation of reserves.

Emits [`FactoryNewPendingEmergencyAdmin`](#factorynewpendingemergencyadmin) event.

✏️Can only be called by the current Emergency Admin

#### function acceptEmergencyAdmin

```solidity
function acceptEmergencyAdmin() external override 
```

The second step in updating the address of the Emergency Admin wallet for VirtuSwap DEX

The Emergency Admin wallet is the only wallet that can set the ReseveRatioWarningThreshold and perform liquidation of reserves.

Emits [`FactoryNewEmergencyAdmin`](#factorynewemergencyadmin) event.

✏️Can only be called by the pending Emergency Admin set by [`setPendingEmergencyAdmin`](#function-setpendingemergencyadmin) method.

#### function setDefaultAllowList

```solidity
function setDefaultAllowList(
    address[] calldata _defaultAllowList
) external override onlyAdmin
```

Sets the default AllowList (see [Allowed Reserves](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/virtuswap-technology/allowed-virtual-reserves)) to be used with for any new pool created with [`createPair`](#createpair) method.

emits [`DefaultAllowListChanged`](#defaultallowlistchanged) event

✏️Can only be called by the Admin

Parameters:

<table><thead><tr><th width="204">Name</th><th width="162">Type</th><th>Description</th></tr></thead><tbody><tr><td>_defaultAllowList</td><td><code>address[]</code></td><td>Array of addresses of tokens that should be accepted as reserves by default</td></tr></tbody></table>

#### function setExchangeReservesAddress

```solidity
function changeAdmin(
    address _exchangeReserves
) external override onlyAdmin
```

Updates the address of the [`vExchangeReserves`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vexchangereserves) contract instance for the `vPairFactory` instance.

✏️Can only be called by the Admin

#### function setVPoolManagerAddress

```solidity
function setVPoolManagerAddress(
      address _vPoolManager
) external override onlyAdminin
```

Sets the active [`vPoolManager`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpoolmanager) instance for the Factory.

Emits [`FactoryVPoolManagerChanged`](#factoryvpoolmanagerchanged) event.

✏️Can only be called by the Admin

## Read-only Functions

#### function pairs

```solidity
function pairs(
    address tokenA,
    address tokenB
) external view returns (address);
```

Given a two tokens, returns the address of the vPair pool between those two tokens.

#### function allPairsLength

```solidity
function allPairsLength() external view override returns (uint256) 
```

Returns the number of Pairs currently available in the system.

#### function getInitCodeHash

```solidity
function getInitCodeHash() external pure returns (bytes32) 
```

Returns the hash of [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) type creation code.

#### function allPairs

```solidity
function allPairs(uint256 index) 
    external view 
returns (address);
```

Returns the array of [`vPair`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpair) instances created by the Factory.

#### function vPoolManager

```solidity
function vPoolManager() 
    external view 
returns (address);
```

Returns the address of [`vPoolManager`](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/dex-contracts/vpoolmanager) instance.

#### function admin

```solidity
function admin() 
    external view 
returns (address);
```

Returns the the address of the Admin wallet. See [Administrative Privileges](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/administrative-privileges).

#### function emergencyAdmin

```solidity
function emergencyAdmin() 
    external view 
returns (address);
```

Returns the the address of the Emergency Admin wallet. See [Administrative Privileges](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/administrative-privileges).

#### function pendingEmergencyAdmin

```solidity
function pendingEmergencyAdmin() 
    external view 
returns (address);
```

Returns the the address of the pending Emergency Admin. See [`setPendingEmergencyAdmin`](#function-setpendingemergencyadmin) and  [Administrative Privileges](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/administrative-privileges).
