I have forked sushiswap recently from the repo. I am getting the following error when calling createPair()
from UniswapV2Factory.sol
during my deployment, the code has not been touched and I have no idea where I am going wrong.
The error:
Error: Returned error: VM Exception while processing transaction: revert
The deployment:
// Uniswap
const Factory = artifacts.require('Uniswapv2/UniswapV2Factory.sol');
// WETH
const WETH = artifacts.require('WETH.sol');
// Testing
const MockERC20 = artifacts.require('MockERC20.sol');
module.exports = async function(deployer, network, accounts) {
const [admin, _] = accounts;
// Test Tokens
const tokenA = await MockERC20.new('TokenA', 'TKA', web3.utils.toWei('100000'));
const tokenB = await MockERC20.new('TokenB', 'TKB', web3.utils.toWei('100000'));
// Uniswap factory
await deployer.deploy(Factory, admin);
const factory = await Factory.deployed();
await factory.createPair(tokenA.address, tokenB.address);
};
CreatePair function:
function createPair(address tokenA, address tokenB) external override returns (address pair) {
require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
bytes memory bytecode = type(UniswapV2Pair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
assembly {
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
UniswapV2Pair(pair).initialize(token0, token1); //<-- this is causing the error
getPair[token0][token1] = pair;
getPair[token1][token0] = pair; // populate mapping in the reverse direction
allPairs.push(pair);
emit PairCreated(token0, token1, pair, allPairs.length);
}
I have deduced that the error is happening here UniswapV2Pair(pair).initialize(token0, token1);
but as to why I have no idea.
Any insights would be much appreciated! James