I am trying to deploy the Uniswap v2 Factory contract on my ganache test network. I have compiled these contracts with my own compiler. But everything I attempt to deploy the Factory, I receive this error c: VM Exception while processing transaction: out of gas
.
When I check the compiledFactory.evm.gasEstimates.creation
here is what I receive : { codeDepositCost: '2155800', executionCost: 'infinite', totalCost: 'infinite' }
.
I have heared problems about deploying the Uni v2 Router contract, but not the factory ? I tried to comment the allPairLength function in the UniswapV2Factory contract, but the result is the same.
Here is the UniswapV2Factory contract that I deploy (pulled from the Uniswap github, so it should be the same):
pragma solidity =0.5.16;
import './interfaces/IUniswapV2Factory.sol';
import './UniswapV2Pair.sol';
contract UniswapV2Factory is IUniswapV2Factory {
address public feeTo;
address public feeToSetter;
mapping(address => mapping(address => address)) public getPair;
address[] public allPairs;
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
constructor(address _feeToSetter) public {
feeToSetter = _feeToSetter;
}
function allPairsLength() external view returns (uint) {
return allPairs.length;
}
function createPair(address tokenA, address tokenB) external 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)
}
IUniswapV2Pair(pair).initialize(token0, token1);
getPair[token0][token1] = pair;
getPair[token1][token0] = pair; // populate mapping in the reverse direction
allPairs.push(pair);
emit PairCreated(token0, token1, pair, allPairs.length);
}
function setFeeTo(address _feeTo) external {
require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
feeTo = _feeTo;
}
function setFeeToSetter(address _feeToSetter) external {
require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
feeToSetter = _feeToSetter;
}
}
here is my test file :
const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const web3 = new Web3(ganache.provider());
const compiledFactory = require("../ethereum/contracts/core/build/UniswapV2Factory.json");
const compiledERC20 = require("../ethereum/contracts/core/build/ERC20.json");
let accounts;
let erc20Contract;
let factory ;
let token1;
let token2;
let token1Address;
let token2Address;
let poolAddress;
beforeEach(async function() {
accounts = await web3.eth.getAccounts();
// console.log(compiledFactory.evm.gasEstimates.creation);
// console.log(compiledFactory);
token1 = await new web3.eth.Contract(compiledERC20.abi).deploy({ data: compiledERC20.evm.bytecode.object, arguments: [100] }).send({ from: accounts[0], gas: "1000000" });
token2 = await new web3.eth.Contract(compiledERC20.abi).deploy({ data: compiledERC20.evm.bytecode.object, arguments: [100] }).send({ from: accounts[0], gas: "1000000" });
factory = await new web3.eth.Contract(compiledFactory.abi).deploy({ data: compiledFactory.evm.bytecode.object, arguments: [accounts[0]] }).send({ from: accounts[0], gas: "1000000" });
token1Address = token1.options.address;
token2Address = token2.options.address;
// poolAddress = factory.methods.createPair(token1Address, token2Address);
});
describe("Tokens", function() {
it("deploy two tokens", () => {
assert.ok(token1.options.address);
assert.ok(token2.options.address);
});
});
describe("Factory", function() {
it("deploy the factory", () => {
assert.ok(factory);
});
it("deploy a liquidity pool", () => {
assert.ok(poolAddress);
});
});
here is my full repo (https://github.com/d-s-i/uniswap-fork) if you want to see the whole code (all contracts, compiled contract, and compile script are in the ethereum/contracts/core folder).
Thanks to anyone for considering helping