# MasterChef

XdYe MasterChef is the smart contract that will reward with XdYe tokens liquidity providers. In other words, MasterChef will be the one capable of minting XdYe in exchange of LPs for a certain pairs.

Those pairs that the MasterChef give rewards can be updated and their multipliers can modified by the address that deploys the XdYe MasterChef.

We have created a diagram that explains the protocol.

&#x20;

<figure><img src="https://1716109615-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaLpsXqP00Znm3KwSX02Z%2Fuploads%2F85OUXFPbcTYM6K8w5I3k%2Fprotocol%20practic.png?alt=media&#x26;token=9d41e62d-18ba-42a9-a538-0a5619699b18" alt=""><figcaption></figcaption></figure>

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

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

### Contract main functions

* *`poolLength()`*

This method returns the length of the pools or LP pairs that XdYe MasterChef contract has set up.

* *`add()`*

This method adds a new LP pair in MasterChef contract, in this function we define the initial *allocationPoint*, the amount of the total XdYe created that will be allocated to this pair we are adding. This function has a parameter *withUpdate* that will update all pools, when user deposits or withdraws LPs. It can only be called by the MasterChef owner.

* *`set()`*

This method allow us to update the allocation point for a specific LP pair that has already been declared on contract. It can only be called by the MasterChef Contract's owner.

* *`setMigrator()`*

This method sets the migrator contract, it can only be called by the MasterChef owner.

* *`migrate()`*

This method migrate LP token to another LP contract. Can be called by anyone.

* *`getMultiplier()`*

This method returns the multiplier applied in XdYe MasterChef in a certain *from - to* time period.

* *`pendingXdYe()`*

This method returns the pending XdYe to be claimed by the user, this function is useful for displaying those rewards on the *front-end.*

* *`massUpdatePools()`*

This method updates reward variables for all pools. The more pools MasterChef contract holds the more expansive this method will be. If the pair was added with, *withUpdate --> true,* then this function will be triggered.

* *`updatePool()`*

This method update reward variables from a the given pool, we reference it through a parameter called *pid = pool ID.*&#x20;

* *`deposit()`*

This method is called once a user wants to deposit LPs of a certain pair already declared in XdYe MasterChef contract.

* *`withdraw()`*

This method is called once a user want to withdraw LPs from a certain pair on MasterChef, this transaction will only success if the user has previously deposited LPs.

* *`emergencyWithdraw()`*

This method allows the user to withdraw his funds without caring about collecting generated rewards.

* *`safeXdYeTransfer()`*

This method checks if the contract has enough XdYe tokens in *balance* before handling an ERC20 transfer.

* *`dev()`*

This method can change the address that is receiving a percentage of the XdYe tokens that are being *minted* as rewards on XdYe MasterChef. In our platform this value has been set to 10%.

{% 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 %}
