Factory.sol 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: BUSL-1.1
  2. pragma solidity 0.7.6;
  3. pragma abicoder v2;
  4. import "@openzeppelin/contracts/math/SafeMath.sol";
  5. import "@openzeppelin/contracts/access/Ownable.sol";
  6. import "./Pool.sol";
  7. contract Factory is Ownable {
  8. using SafeMath for uint256;
  9. //---------------------------------------------------------------------------
  10. // VARIABLES
  11. mapping(uint256 => Pool) public getPool; // poolId -> PoolInfo
  12. address[] public allPools;
  13. address public immutable router;
  14. address public defaultFeeLibrary; // address for retrieving fee params for swaps
  15. //---------------------------------------------------------------------------
  16. // MODIFIERS
  17. modifier onlyRouter() {
  18. require(msg.sender == router, "Mirrorgate: caller must be Router.");
  19. _;
  20. }
  21. constructor(address _router) {
  22. require(_router != address(0x0), "Mirrorgate: _router cant be 0x0"); // 1 time only
  23. router = _router;
  24. }
  25. function setDefaultFeeLibrary(address _defaultFeeLibrary) external onlyOwner {
  26. require(_defaultFeeLibrary != address(0x0), "Mirrorgate: fee library cant be 0x0");
  27. defaultFeeLibrary = _defaultFeeLibrary;
  28. }
  29. function allPoolsLength() external view returns (uint256) {
  30. return allPools.length;
  31. }
  32. function createPool(
  33. uint256 _poolId,
  34. address _token,
  35. uint8 _sharedDecimals,
  36. uint8 _localDecimals,
  37. string memory _name,
  38. string memory _symbol
  39. ) public onlyRouter returns (address poolAddress) {
  40. require(address(getPool[_poolId]) == address(0x0), "Mirrorgate: Pool already created");
  41. Pool pool = new Pool(_poolId, router, _token, _sharedDecimals, _localDecimals, defaultFeeLibrary, _name, _symbol);
  42. getPool[_poolId] = pool;
  43. poolAddress = address(pool);
  44. allPools.push(poolAddress);
  45. }
  46. function renounceOwnership() public override onlyOwner {}
  47. }