# Factory

Factory contract is used to **create exchange contracts** (Pairs) **for any ERC20 tokens that do not have one** in XdYe.&#x20;

It also used as a registry of ERC20 tokens (LPs) that have been added to the system, and the corresponding (Pair) exchange contract which they are associated.&#x20;

Something that someone can think is how can Pairs be differentiated from one DEX to another, this is why ***init code hash***, it is important, you can see how to set it and get in deep with this concept in  [factory-deployment](https://rogercapone.gitbook.io/xdye-documentation/xdye-deployment/factory-deployment "mention").

**XdYe Factory** Smart Contract can be found at:&#x20;

{% embed url="<https://github.com/rogerCapone/XdYe_Smart_Contracts/blob/main/XdYeFactory.sol>" %}
XdYe Factory Contract Source Code
{% endembed %}

### Contract main functions

* *`createPair()`*

This method is used for generating a new Pair contract for a token pair. If the contract Pair has already been created transaction reverts, this way we assure that there is only ONE pair (exchange contract) for that ERC20 pair.

* *`setFeeTo()`*

This method is used for replacing the address that receives the trading fees generated from XdYe swaps. This change can only be done for address stored inside the Factory contract as *feeToSetter.*&#x20;

* *`setMigrator`*`()`

This method is used for replacing the address that holds the capability of migrating.

* *`setFeeToSetter()`*

This method is used for governance of the address that can change the *FeeToSetter* variable. Or in other words the one that has the capability to define who is going to receive trading fees generated.

{% hint style="warning" %}
**Attention:** If you are trying to replicate the code, be sure to consider the imports or visit the corresponding [Github Repository](https://github.com/rogerCapone/XdYe_Smart_Contracts/tree/main) in order to have the whole source code.
{% endhint %}
