|
| 1 | +//SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | +pragma solidity 0.8.15; |
| 3 | + |
| 4 | +import '@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol'; |
| 5 | +import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; |
| 6 | +import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; |
| 7 | + |
| 8 | +import './Campaign.sol'; |
| 9 | + |
| 10 | +import 'hardhat/console.sol'; |
| 11 | +import './interface/ICampaignFactory.sol'; |
| 12 | + |
| 13 | +contract CampaignFactoryUpgradable is ICampaignFactory, UUPSUpgradeable, OwnableUpgradeable { |
| 14 | + // White list mapping |
| 15 | + mapping(address => bool) public whiteUsers; |
| 16 | + |
| 17 | + // White list token mapping |
| 18 | + mapping(IERC20 => bool) public whiteTokens; |
| 19 | + |
| 20 | + function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} |
| 21 | + |
| 22 | + function initialize() public initializer { |
| 23 | + __Ownable_init_unchained(); |
| 24 | + } |
| 25 | + |
| 26 | + function modifyWhiteUser(address user, bool status) public onlyOwner { |
| 27 | + whiteUsers[user] = status; |
| 28 | + emit EvWhiteUserSet(user, status); |
| 29 | + } |
| 30 | + |
| 31 | + function modifyWhiteToken(IERC20 token, bool status) public onlyOwner { |
| 32 | + whiteTokens[token] = status; |
| 33 | + emit EvWhiteTokenSet(token, status); |
| 34 | + } |
| 35 | + |
| 36 | + function createCampaign( |
| 37 | + IERC20 token, |
| 38 | + uint256 amount, |
| 39 | + string memory name, |
| 40 | + string memory symbol |
| 41 | + ) public override onlyWhiteUser onlyWhiteToken(token) returns (bool) { |
| 42 | + Campaign cam = new Campaign(token, amount, name, symbol); |
| 43 | + emit EvCampaignCreated(msg.sender, address(cam)); |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | + modifier onlyWhiteUser() { |
| 48 | + require(whiteUsers[msg.sender], 'CampaignFactory: not whitelist'); |
| 49 | + _; |
| 50 | + } |
| 51 | + |
| 52 | + modifier onlyWhiteToken(IERC20 token) { |
| 53 | + require(whiteTokens[token], 'CampaignFactory: not whitelist'); |
| 54 | + _; |
| 55 | + } |
| 56 | +} |
0 commit comments