BFactory.sol

Created Diff never expires
5 removals
80 lines
60 additions
136 lines
// This program is free software: you can redistribute it and/or modify
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// (at your option) any later version.


// This program is disstributed in the hope that it will be useful,
// This program is disstributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// GNU General Public License for more details.


// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// along with this program. If not, see <http://www.gnu.org/licenses/>.


pragma solidity 0.5.12;
pragma solidity 0.5.12;


// Builds new BPools, logging their addresses and providing `isBPool(address) -> (bool)`
// Builds new BPools, logging their addresses and providing `isBPool(address) -> (bool)`


import "./BPool.sol";
import "./BPool.sol";


contract BFactory is BBronze {
contract BFactory is BBronze {
event LOG_NEW_POOL(
event LOG_NEW_POOL(
address indexed caller,
address indexed caller,
address indexed pool
address indexed pool
);
);


event LOG_BLABS(
event LOG_BLABS(
address indexed caller,
address indexed caller,
address indexed blabs
address indexed blabs
);
);


event LOG_RESERVES_ADDRESS(
address indexed caller,
address indexed reservesAddress
);

event LOG_ALLOW_NON_ADMIN_POOL(
address indexed caller,
bool allow
);

mapping(address=>bool) private _isBPool;
mapping(address=>bool) private _isBPool;


function isBPool(address b)
function isBPool(address b)
external view returns (bool)
external view returns (bool)
{
{
return _isBPool[b];
return _isBPool[b];
}
}


function newBPool()
function newBPool()
external
external
returns (BPool)
returns (BPool)
{
{
if (!_allowNonAdminPool) {
require(msg.sender == _blabs);
}
BPool bpool = new BPool();
BPool bpool = new BPool();
_isBPool[address(bpool)] = true;
_isBPool[address(bpool)] = true;
emit LOG_NEW_POOL(msg.sender, address(bpool));
emit LOG_NEW_POOL(msg.sender, address(bpool));
bpool.setController(msg.sender);
bpool.setController(msg.sender);
return bpool;
return bpool;
}
}


address private _blabs;
address private _blabs;
address private _reservesAddress;

bool private _allowNonAdminPool;


constructor() public {
constructor() public {
_blabs = msg.sender;
_blabs = msg.sender;
_reservesAddress = msg.sender;
_allowNonAdminPool = false;
}

function getAllowNonAdminPool()
external view
returns (bool)
{
return _allowNonAdminPool;
}

function setAllowNonAdminPool(bool b)
external
{
require(msg.sender == _blabs, "ERR_NOT_BLABS");
emit LOG_ALLOW_NON_ADMIN_POOL(msg.sender, b);
_allowNonAdminPool = b;
}
}


function getBLabs()
function getBLabs()
external view
external view
returns (address)
returns (address)
{
{
return _blabs;
return _blabs;
}
}


function setBLabs(address b)
function setBLabs(address b)
external
external
{
{
require(msg.sender == _blabs, "ERR_NOT_BLABS");
require(msg.sender == _blabs);
emit LOG_BLABS(msg.sender, b);
emit LOG_BLABS(msg.sender, b);
_blabs = b;
_blabs = b;
}

function getReservesAddress()
external view
returns (address)
{
return _reservesAddress;
}

function setReservesAddress(address a)
external
{
require(msg.sender == _blabs);
emit LOG_RESERVES_ADDRESS(msg.sender, a);
_reservesAddress = a;
}
}


function collect(BPool pool)
function collect(BPool pool)
external
external
{
{
require(msg.sender == _blabs, "ERR_NOT_BLABS");
require(msg.sender == _blabs);
require(_isBPool[address(pool)]);
uint collected = IERC20(pool).balanceOf(address(this));
uint collected = IERC20(pool).balanceOf(address(this));
bool xfer = pool.transfer(_blabs, collected);
bool xfer = pool.transfer(_blabs, collected);
require(xfer, "ERR_ERC20_FAILED");
require(xfer);
}
}
}


function collectTokenReserves(BPool pool)
external
{
require(msg.sender == _blabs);
require(_isBPool[address(pool)]);
pool.drainTotalReserves(_reservesAddress);
}
}