I am trying to use the deploy
function in the Create2.sol
library contract. I am getting the Create2: Failed on deploy
revert.
Environment
Using buidler framework. v1.3.2
Using OZ contracts v3.0.1
Using buidler/truffle5 plugin v1.3.1
Details
I’m not entirely sure why its failing to deploy, the stack traces show it failing on L35 of the Create2.sol file.
Code to reproduce
The code for the test:
contract("Registry and Factory Contract", (accounts) => {
// ACCOUNTS
const Alice = accounts[0];
let factory, tokenU, tokenS, base, quote, expiry;
before(async () => {
factory = await Factory.new(Alice);
tokenU = await newERC20("TEST DAI", "DAI", MILLION_ETHER);
tokenS = await newWeth();
base = toWei("200");
quote = toWei("1");
expiry = "1690868800"; // May 30, 2020, 8PM UTC
});
describe("Registry", () => {
it("should deploy the contract", async () => {
await factory.deploy(
tokenU.address,
tokenS.address,
base,
quote,
expiry
);
});
});
});
The code for the factory contract:
import { Option, SafeMath } from "../../primitives/Option.sol";
import "../../interfaces/IFactory.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import { Create2 } from "@openzeppelin/contracts/utils/Create2.sol";
contract Factory is IFactory, Ownable {
using SafeMath for uint;
constructor(address registry) public { transferOwnership(registry); }
function deploy(address tokenU, address tokenS, uint base, uint quote, uint expiry)
external
override
onlyOwner
returns (address option)
{
bytes memory bytecode = type(Option).creationCode;
bytes32 salt = keccak256(abi.encodePacked(tokenU, tokenS, base, quote, expiry));
option = Create2.deploy(uint(0), salt, bytecode);
}
}