From a9f78c6264a94aec09ec1456ed616a7532981a5f Mon Sep 17 00:00:00 2001 From: Brice Stacey Date: Tue, 20 Sep 2022 11:18:09 -0400 Subject: [PATCH] Add basic PoolFactory --- contracts/Pool.sol | 10 ++++++++++ contracts/PoolFactory.sol | 27 +++++++++++++++++++++++++++ test/PoolFactory.test.ts | 22 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 contracts/Pool.sol create mode 100644 contracts/PoolFactory.sol create mode 100644 test/PoolFactory.test.ts diff --git a/contracts/Pool.sol b/contracts/Pool.sol new file mode 100644 index 00000000..5336b3af --- /dev/null +++ b/contracts/Pool.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.16; + +/** + * @title Pool + * + * Empty Pool contract. + */ +contract Pool { +} diff --git a/contracts/PoolFactory.sol b/contracts/PoolFactory.sol new file mode 100644 index 00000000..f7a0740b --- /dev/null +++ b/contracts/PoolFactory.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.16; + +import "./Pool.sol"; + +/** + * @title PoolFactory + */ +contract PoolFactory { + + /** + * @dev Emitted when a pool is created. + */ + event PoolCreated(address indexed addr); + + /** + * @dev Creates a pool + * @dev Emits `PoolCreated` event. + */ + function createPool() external returns (address poolAddress) { + Pool pool = new Pool(); + address addr = address(pool); + emit PoolCreated(addr); + return addr; + } + +} diff --git a/test/PoolFactory.test.ts b/test/PoolFactory.test.ts new file mode 100644 index 00000000..c3696e3d --- /dev/null +++ b/test/PoolFactory.test.ts @@ -0,0 +1,22 @@ +import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; +import { expect } from "chai"; +import { ethers } from "hardhat"; + +describe("PoolFactory", () => { + async function deployFixture() { + const PoolFactory = await ethers.getContractFactory("PoolFactory"); + const poolFactory = await PoolFactory.deploy(); + await poolFactory.deployed(); + + return { + poolFactory + }; + } + + it("emits PoolCreated", async () => { + const { poolFactory } = await loadFixture(deployFixture); + await expect(poolFactory.createPool()) + .to.emit(poolFactory, "PoolCreated"); + }); + +});