forked from balancer/balancer-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBFactory.sol
73 lines (63 loc) · 2.06 KB
/
BFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.25;
import {BPool} from './BPool.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import {IBFactory} from 'interfaces/IBFactory.sol';
import {IBPool} from 'interfaces/IBPool.sol';
/**
* @title BFactory
* @notice Creates new BPools, logging their addresses and acting as a registry of pools.
*/
contract BFactory is IBFactory {
/// @dev Mapping indicating whether the address is a BPool.
mapping(address => bool) internal _isBPool;
/// @dev bDao address.
address internal _bDao;
constructor() {
_bDao = msg.sender;
}
/// @inheritdoc IBFactory
function newBPool(string memory name, string memory symbol) external returns (IBPool bPool) {
bPool = _newBPool(name, symbol);
_isBPool[address(bPool)] = true;
emit LOG_NEW_POOL(msg.sender, address(bPool));
bPool.setController(msg.sender);
}
/// @inheritdoc IBFactory
function setBDao(address bDao) external {
if (bDao == address(0)) {
revert BFactory_AddressZero();
}
if (msg.sender != _bDao) {
revert BFactory_NotBDao();
}
emit LOG_BDAO(msg.sender, bDao);
_bDao = bDao;
}
/// @inheritdoc IBFactory
function collect(IBPool bPool) external virtual {
if (msg.sender != _bDao) {
revert BFactory_NotBDao();
}
uint256 collected = bPool.balanceOf(address(this));
SafeERC20.safeTransfer(bPool, _bDao, collected);
}
/// @inheritdoc IBFactory
function isBPool(address bPool) external view returns (bool) {
return _isBPool[bPool];
}
/// @inheritdoc IBFactory
function getBDao() external view returns (address) {
return _bDao;
}
/**
* @notice Deploys a new BPool.
* @param name The name of the Pool ERC20 token
* @param symbol The symbol of the Pool ERC20 token
* @dev Internal function to allow overriding in derived contracts.
* @return bPool The deployed BPool
*/
function _newBPool(string memory name, string memory symbol) internal virtual returns (IBPool bPool) {
bPool = new BPool(name, symbol);
}
}