1

I'm trying to locally deploy a contract similar to sushiswap, but I keep getting a revert from addLiquidityETH(), no message other than VM Exception while processing transaction: revert

//module.exports = function(deployer) {};
const SushiToken = artifacts.require("SushiToken");
const MasterChef = artifacts.require("MasterChef");
const SushiBar = artifacts.require("SushiBar");
const UniswapFactory = artifacts.require("UniSwapV2Factory");
const UniswapRouter = artifacts.require("UniswapV2Router02");
const MockERC20 = artifacts.require("MockERC20");
const SushiMaker = artifacts.require("SushiMaker");

const migration = async function(deployer,network,accounts) {
    await Promise.all([
        deployToken(deployer,network,accounts),
    ]);
};

module.exports = migration;

async function deployToken(deployer,network,accounts) {

    if( network === 'test' ) {
        
        dev_addr = accounts[9];
        account1 = accounts[8];

        await deployer.deploy(SushiToken);
        let sushiToken = await SushiToken.deployed();

        await deployer.deploy(MasterChef, SushiToken.address, dev_addr, 25, 0, 0);
        await deployer.deploy(SushiBar, SushiToken.address);

        let factory = await deployer.deploy(UniswapFactory, dev_addr);
        let wethToken = await deployer.deploy(MockERC20, "Wrapped Ether", "WETH", 1000);
        let anotherToken = await deployer.new(MockERC20, "Another Token", "AT", 1000000000000); 

        let poolToken = 0x0;
        if(( (await factory.getPair(wethToken.address, anotherToken.address)).toString()) === '0x0000000000000000000000000000000000000000') {
            poolToken = await factory.createPair(wethToken.address, anotherToken.address);
        }
     
        let router = await deployer.deploy(UniswapRouter, UniswapFactory.address, dev_addr);

        await deployer.deploy(SushiMaker, UniswapFactory.address, SushiBar.address, SushiToken.address, wethToken.address);


        await sushiToken.approve( accounts[0], 10000000000);
        await sushiToken.mint(accounts[0], 10000000000);

        try { // the error is somewhere in here
            await router.addLiquidityETH( 
                sushiToken.address, 
                100, 
                50,
                9000,
                accounts[0], 
                ~~((Date.now() + 1000*24*60*60) / 1000), // unix date 24h into the future
                {from: accounts[0], value: 10000, gas: 6000000}
            );
            
        } catch(err){
            console.error(err)
        }
    } 

}

I have tried different addressess too, as well as different amounts, but so far it always reverts.

// Edit: accounts[0] through accounts[9] have roughly 100 ETH per account.

13
  • What is ~~((Date.now() + 1000*24*60*60) / 1000)? – goodvibration Oct 8 '20 at 15:54
  • that's a unix date, exactly 24 hours into the future. – Zimri Leijen Oct 8 '20 at 15:55
  • What does ~~ does? – goodvibration Oct 8 '20 at 15:56
  • The same as Math.floor() – Zimri Leijen Oct 8 '20 at 15:56
  • And do you have 10000 wei in accounts[0]? – goodvibration Oct 8 '20 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.