How to use UNI-V2 token rather than sushi LP token to stake and what is _pid inside Masterchef.sol file from sushi swap?

Hello every one I'm new to this Defi field , I was trying to clone uniswap to learn how things work . I cloned uniswap and also create frontend with react , It's to perform functionalities like transfering tokens to others, adding liquidity and swapping tokens to tokens , remove liquidity from the pool . I want to implement yield farming functionaity . So I was going through the smartcontracts of sushiswap . The thing is I want to use UNI-V2 LP token rather than "sushi LP token" for staking or depositing tokens to get "SUSHI" token . Inside Masterchef.sol file of sushi swap there's a function for staking tokens,

 function deposit(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending =
                user.amount.mul(pool.accSushiPerShare).div(1e12).sub(
                    user.rewardDebt
                );
            safeSushiTransfer(msg.sender, pending);
        }
        pool.lpToken.safeTransferFrom(
            address(msg.sender),
            address(this),
            _amount
        );
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }

I'm not able to understand what is the pool id how would I get this ? How pool Id is decided ? how can I call this function in frontend ?

I was going through the frontend of sushi swap or uniswap too but it's really huge to understand.
Thanks .

There're "poolLength" and "poolInfo" in the masterchef contract. poolLength is the amount of all the pools. And poolInfo is the info of each pool, which you could pass pid to look up the info of the pool such as allotPoint. The range of pid is from 0 to poolLength - 1. The order of pid is depend on the order you call the add() function.

okay , let's say I've added liquidity for TK1 and TK2 tokens and got some UNI-V2 LP tokens in return and I want to deposit that LP token .
Then there should be a deposit function on react side fetched from contract's abis , then the pid of that pool would be automatically known , that pool index?
You said " you could pass pid to look up the info of the pool" but how can I get that pid value ?

You should call add() function first to add you lp info to the masterchef contract. If you want to add 3 lp tokens to chef. You will have to call the add() function 3 times. And the pid of each lp is from 0 to 2 and it's depend on the order of your call.

1 Like

thanks , I'll work on it

Other DEX platforms they have a huge no of token pairs possibiliies to provide liquidity like : tk1/tk2 , tk1/tk3 , ........, tkn/tk(n-1) . So, I have to call add() that number of times at the time of deployment ?

As far as I know, Yes

I want to ask one more thing ,
the solidity version of cloned uniswap is mostly on version 0.5.16 but the yield farming of sushi swap was made on 0.6.12 so I thought that just by including this version on hardhat config it would be good but it says :

The Solidity version pragma statement in these files don't match any of the configured compilers in your config. Change the pragma or configure additional compiler versions in your hardhat config.

  * contracts/core/libraries/SafeMath.sol (=0.5.16)
  * contracts/core/test/ERC20.sol (=0.5.16)
  * contracts/core/libraries/UQ112x112.sol (=0.5.16)

These files import other files that use a different and incompatible version of Solidity:

  * contracts/core/UniswapV2Pair.sol (=0.6.12) imports contracts/core/libraries/UQ112x112.sol (=0.5.16)
  * contracts/core/UniswapV2ERC20.sol (=0.6.12) imports contracts/core/libraries/SafeMath.sol (=0.5.16)

These files depend on other files that use a different and incompatible version of Solidity:

  * contracts/sushi/mocks/SushiSwapPairMock.sol (0.6.12) depends on contracts/core/libraries/UQ112x112.sol (=0.5.16) and contracts/core/libraries/SafeMath.sol (=0.5.16)
  * contracts/sushi/SushiRoll.sol (0.6.12) depends on contracts/periphery/libraries/SafeMath.sol (=0.6.6)
  * contracts/core/UniswapV2Factory.sol (=0.6.12) depends on contracts/core/libraries/UQ112x112.sol (=0.5.16) and contracts/core/libraries/SafeMath.sol (=0.5.16)
  * contracts/sushi/mocks/SushiSwapFactoryMock.sol (0.6.12) depends on contracts/core/libraries/UQ112x112.sol (=0.5.16) and contracts/core/libraries/SafeMath.sol (=0.5.16)

To learn more, run the command again with --verbose

Read about compiler configuration at https://hardhat.org/config

so I thought to just change the version of the sol files of router and factory of uniswap , then it says


contracts/core/UniswapV2Pair.sol:38:5: TypeError: Overriding function is missing "override" specifier.
    function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:40:5: Overridden function is here:
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    ^-----------------------------------------------------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:66:5: TypeError: Overriding function is missing "override" specifier.
    function initialize(address _token0, address _token1) external {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:51:5: Overridden function is here:
    function initialize(address, address) external;
    ^---------------------------------------------^

contracts/core/UniswapV2Pair.sol:110:5: TypeError: Overriding function is missing "override" specifier.
    function mint(address to) external lock returns (uint liquidity) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:45:5: Overridden function is here:
    function mint(address to) external returns (uint liquidity);
    ^----------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:134:5: TypeError: Overriding function is missing "override" specifier.
    function burn(address to) external lock returns (uint amount0, uint amount1) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:46:5: Overridden function is here:
    function burn(address to) external returns (uint amount0, uint amount1);
    ^----------------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:159:5: TypeError: Overriding function is missing "override" specifier.
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:47:5: Overridden function is here:
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    ^----------------------------------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:190:5: TypeError: Overriding function is missing "override" specifier.
    function skim(address to) external lock {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:48:5: Overridden function is here:
    function skim(address to) external;
    ^---------------------------------^

contracts/core/UniswapV2Pair.sol:198:5: TypeError: Overriding function is missing "override" specifier.
    function sync() external lock {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:49:5: Overridden function is here:
    function sync() external;
    ^-----------------------^

contracts/core/UniswapV2Pair.sol:15:5: TypeError: Overriding public state variable is missing "override" specifier.
    uint public constant MINIMUM_LIQUIDITY = 10**3;
    ^--------------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:36:5: Overridden public state variable is here:
    function MINIMUM_LIQUIDITY() external pure returns (uint);
    ^--------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:18:5: TypeError: Overriding public state variable is missing "override" specifier.
    address public factory;
    ^--------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:37:5: Overridden public state variable is here:
    function factory() external view returns (address);
    ^-------------------------------------------------^

contracts/core/UniswapV2Pair.sol:19:5: TypeError: Overriding public state variable is missing "override" specifier.
    address public token0;
    ^-------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:38:5: Overridden public state variable is here:
    function token0() external view returns (address);
    ^------------------------------------------------^

contracts/core/UniswapV2Pair.sol:20:5: TypeError: Overriding public state variable is missing "override" specifier.
    address public token1;
    ^-------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:39:5: Overridden public state variable is here:
    function token1() external view returns (address);
    ^------------------------------------------------^

contracts/core/UniswapV2Pair.sol:26:5: TypeError: Overriding public state variable is missing "override" specifier.
    uint public price0CumulativeLast;
    ^------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:41:5: Overridden public state variable is here:
    function price0CumulativeLast() external view returns (uint);
    ^-----------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:27:5: TypeError: Overriding public state variable is missing "override" specifier.
    uint public price1CumulativeLast;
    ^------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:42:5: Overridden public state variable is here:
    function price1CumulativeLast() external view returns (uint);
    ^-----------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:28:5: TypeError: Overriding public state variable is missing "override" specifier.
    uint public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event
    ^---------------^
contracts/core/interfaces/IUniswapV2Pair.sol:43:5: Overridden public state variable is here:
    function kLast() external view returns (uint);
    ^--------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "DOMAIN_SEPARATOR". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:19:5: Definition in "UniswapV2ERC20":
    bytes32 public DOMAIN_SEPARATOR;
    ^-----------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:18:5: Definition in "IUniswapV2Pair":
    function DOMAIN_SEPARATOR() external view returns (bytes32);
    ^----------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "PERMIT_TYPEHASH". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:21:5: Definition in "UniswapV2ERC20":
    bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
    ^----------------------------------------------------------------------------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:19:5: Definition in "IUniswapV2Pair":
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    ^---------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "allowance". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:17:5: Definition in "UniswapV2ERC20":
    mapping(address => mapping(address => uint)) public allowance;
    ^-----------------------------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:12:5: Definition in "IUniswapV2Pair":
    function allowance(address owner, address spender) external view returns (uint);
    ^------------------------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "approve". Two or more base classes define function with same name and parameter types.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:66:5: Definition in "UniswapV2ERC20":
    function approve(address spender, uint value) external returns (bool) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:14:5: Definition in "IUniswapV2Pair":
    function approve(address spender, uint value) external returns (bool);
    ^--------------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "balanceOf". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:16:5: Definition in "UniswapV2ERC20":
    mapping(address => uint) public balanceOf;
    ^---------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:11:5: Definition in "IUniswapV2Pair":
    function balanceOf(address owner) external view returns (uint);
    ^-------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "decimals". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:14:5: Definition in "UniswapV2ERC20":
    uint8 public constant decimals = 18;
    ^---------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:9:5: Definition in "IUniswapV2Pair":
    function decimals() external pure returns (uint8);
    ^------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "name". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:12:5: Definition in "UniswapV2ERC20":
    string public constant name = 'Uniswap V2';
    ^----------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:7:5: Definition in "IUniswapV2Pair":
    function name() external pure returns (string memory);
    ^----------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "nonces". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:22:5: Definition in "UniswapV2ERC20":
    mapping(address => uint) public nonces;
    ^------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:20:5: Definition in "IUniswapV2Pair":
    function nonces(address owner) external view returns (uint);
    ^----------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "permit". Two or more base classes define function with same name and parameter types.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:84:5: Definition in "UniswapV2ERC20":
    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:22:5: Definition in "IUniswapV2Pair":
    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
    ^-----------------------------------------------------------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "symbol". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:13:5: Definition in "UniswapV2ERC20":
    string public constant symbol = 'UNI-V2';
    ^--------------------------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:8:5: Definition in "IUniswapV2Pair":
    function symbol() external pure returns (string memory);
    ^------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "totalSupply". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:15:5: Definition in "UniswapV2ERC20":
    uint  public totalSupply;
    ^----------------------^
contracts/core/interfaces/IUniswapV2Pair.sol:10:5: Definition in "IUniswapV2Pair":
    function totalSupply() external view returns (uint);
    ^--------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "transfer". Two or more base classes define function with same name and parameter types.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:71:5: Definition in "UniswapV2ERC20":
    function transfer(address to, uint value) external returns (bool) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:15:5: Definition in "IUniswapV2Pair":
    function transfer(address to, uint value) external returns (bool);
    ^----------------------------------------------------------------^

contracts/core/UniswapV2Pair.sol:11:1: TypeError: Derived contract must override function "transferFrom". Two or more base classes define function with same name and parameter types.
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
^ (Relevant source part starts here and spans across multiple lines).
contracts/core/UniswapV2ERC20.sol:76:5: Definition in "UniswapV2ERC20":
    function transferFrom(address from, address to, uint value) external returns (bool) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Pair.sol:16:5: Definition in "IUniswapV2Pair":
    function transferFrom(address from, address to, uint value) external returns (bool);
    ^----------------------------------------------------------------------------------^

contracts/core/UniswapV2Factory.sol:21:5: TypeError: Overriding function is missing "override" specifier.
    function allPairsLength() external view returns (uint) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Factory.sol:12:5: Overridden function is here:
    function allPairsLength() external view returns (uint);
    ^-----------------------------------------------------^

contracts/core/UniswapV2Factory.sol:25:5: TypeError: Overriding function is missing "override" specifier.
    function createPair(address tokenA, address tokenB) external returns (address pair) {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Factory.sol:14:5: Overridden function is here:
    function createPair(address tokenA, address tokenB) external returns (address pair);
    ^----------------------------------------------------------------------------------^

contracts/core/UniswapV2Factory.sol:42:5: TypeError: Overriding function is missing "override" specifier.
    function setFeeTo(address _feeTo) external {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Factory.sol:16:5: Overridden function is here:
    function setFeeTo(address) external;
    ^----------------------------------^

contracts/core/UniswapV2Factory.sol:47:5: TypeError: Overriding function is missing "override" specifier.
    function setFeeToSetter(address _feeToSetter) external {
    ^ (Relevant source part starts here and spans across multiple lines).
contracts/core/interfaces/IUniswapV2Factory.sol:17:5: Overridden function is here:
    function setFeeToSetter(address) external;
    ^----------------------------------------^

contracts/core/UniswapV2Factory.sol:9:5: TypeError: Overriding public state variable is missing "override" specifier.
    address public feeTo;
    ^------------------^
contracts/core/interfaces/IUniswapV2Factory.sol:7:5: Overridden public state variable is here:
    function feeTo() external view returns (address);
    ^-----------------------------------------------^

contracts/core/UniswapV2Factory.sol:10:5: TypeError: Overriding public state variable is missing "override" specifier.
    address public feeToSetter;
    ^------------------------^
contracts/core/interfaces/IUniswapV2Factory.sol:8:5: Overridden public state variable is here:
    function feeToSetter() external view returns (address);
    ^-----------------------------------------------------^

contracts/core/UniswapV2Factory.sol:12:5: TypeError: Overriding public state variable is missing "override" specifier.
    mapping(address => mapping(address => address)) public getPair;
    ^------------------------------------------------------------^
contracts/core/interfaces/IUniswapV2Factory.sol:10:5: Overridden public state variable is here:
    function getPair(address tokenA, address tokenB) external view returns (address pair);
    ^------------------------------------------------------------------------------------^

contracts/core/UniswapV2Factory.sol:13:5: TypeError: Overriding public state variable is missing "override" specifier.
    address[] public allPairs;
    ^-----------------------^
contracts/core/interfaces/IUniswapV2Factory.sol:11:5: Overridden public state variable is here:
    function allPairs(uint) external view returns (address pair);
    ^-----------------------------------------------------------^

Error HH600: Compilation failed

For more info go to https://hardhat.org/HH600 or run Hardhat with --show-stack-traces

Now there are lot of missing override problems .

1 Like

Yes. You should learn more about solidity

yeah , I have to learn about latest version

I got the same error as you, do you have the answer yet?

I got the same error as you, do you have the answer yet?

  * contracts/Greeter.sol (^0.7.6) imports @openzeppelin/contracts/token/ERC20/ERC20.sol (^0.8.0), @openzeppelin/contracts/access/Ownable.sol (^0.8.0) and 1 other file. Use --verbose to see the full list.

The MasterChef.add(...) has to be called for adding every single LP token into farming (MasterChef)? If I have 100 LP token, I'll call MasterChef.add(...) 100 times or what?

What's MasterChef.deposit(...) for then? When is it used?