|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +pragma solidity ^0.8.0; |
| 4 | + |
| 5 | +import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; |
| 6 | +import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; |
| 7 | +import "@openzeppelin/contracts/utils/Context.sol"; |
| 8 | +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 9 | + |
| 10 | + |
| 11 | +contract MatchingPool is OwnableUpgradeable { |
| 12 | + |
| 13 | + event AdminAdded(address _admin); |
| 14 | + event AdminRemoved(address _admin); |
| 15 | + event MatchingPoolFilled(uint256 amount); |
| 16 | + |
| 17 | + event MatchingPoolDonation(address sender, uint256 value, uint256 roundId); |
| 18 | + event MatchingPoolDonationToken(address sender, uint256 value, uint256 roundId, address token); |
| 19 | + event Distribute(address to, uint256 amount, uint256 roundId, address token); |
| 20 | + event DistributeRound(uint256 roundId, uint256 amount, address token); |
| 21 | + |
| 22 | + mapping(address => bool) public isAdmin; |
| 23 | + |
| 24 | + address public multisigAddress; |
| 25 | + |
| 26 | + function construct(address _multisigAddress) external initializer { |
| 27 | + __Ownable_init(); // Add this line to initialize the OwnableUpgradeable contract |
| 28 | + multisigAddress = _multisigAddress; |
| 29 | + } |
| 30 | + |
| 31 | + function setMultisigAddress(address _multisigAddress) external onlyMultisig { |
| 32 | + multisigAddress = _multisigAddress; |
| 33 | + } |
| 34 | + |
| 35 | + function fillUpMatchingPool(uint256 roundId) public payable onlyAdmin { |
| 36 | + require(msg.value > 0, "MVPCLR:fillUpMatchingPool - No value provided"); |
| 37 | + emit MatchingPoolDonation(msg.sender, msg.value, roundId); |
| 38 | + } |
| 39 | + |
| 40 | + function fillUpMatchingPoolToken(address from, address token, uint amount, uint256 roundId) public onlyAdmin { |
| 41 | + require(amount > 0, "MVPCLR:fillUpMatchingPoolToken - No amount provided"); |
| 42 | + |
| 43 | + IERC20(token).transferFrom(from, address(this), amount); |
| 44 | + |
| 45 | + emit MatchingPoolDonationToken(from, amount, roundId, token); |
| 46 | + } |
| 47 | + |
| 48 | + function addAdmin(address _admin) public onlyOwner { |
| 49 | + isAdmin[_admin] = true; |
| 50 | + emit AdminAdded(_admin); |
| 51 | + } |
| 52 | + |
| 53 | + function removeAdmin(address _admin) public onlyOwner { |
| 54 | + require(isAdmin[_admin], "Admin not found"); |
| 55 | + delete isAdmin[_admin]; |
| 56 | + emit AdminRemoved(_admin); |
| 57 | + } |
| 58 | + |
| 59 | + function distribute(address payable[] memory patrons, uint[] memory amounts, address token, uint256 roundId) public onlyAdmin { |
| 60 | + require(patrons.length == amounts.length, "Length of patrons and amounts must be the same"); |
| 61 | + uint256 totalAmount = 0; // Store total amount to be distributed |
| 62 | + |
| 63 | + // Loop through the list of patrons and distribute the funds to each address |
| 64 | + for (uint i = 0; i < patrons.length; i++) { |
| 65 | + if (token == address(0)) |
| 66 | + patrons[i].transfer(amounts[i]); // Reverts transaction if transfer fails |
| 67 | + else |
| 68 | + IERC20(token).transfer(patrons[i], amounts[i]); |
| 69 | + emit Distribute(patrons[i], amounts[i], roundId, token); |
| 70 | + totalAmount += amounts[i]; // Add the amount to totalAmount |
| 71 | + } |
| 72 | + emit DistributeRound(roundId, totalAmount, token); |
| 73 | + } |
| 74 | + |
| 75 | + function withdrawFunds(uint256 amount) external onlyMultisig { |
| 76 | + require(address(this).balance >= amount, "Insufficient funds in contract"); |
| 77 | + payable(multisigAddress).transfer(amount); |
| 78 | + } |
| 79 | + |
| 80 | + function withdrawERC20Funds(uint256 amount, address token) external onlyMultisig { |
| 81 | + IERC20(token).transfer(msg.sender, amount); |
| 82 | + } |
| 83 | + |
| 84 | + modifier onlyAdmin() { |
| 85 | + require(isAdmin[msg.sender] == true, "Not an admin"); |
| 86 | + _; |
| 87 | + } |
| 88 | + |
| 89 | + modifier onlyMultisig() { |
| 90 | + require(msg.sender == multisigAddress, "Not authorized"); |
| 91 | + _; |
| 92 | + } |
| 93 | + |
| 94 | +} |
0 commit comments