-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from The-Poolz/fee-issue
made PayFee public
- Loading branch information
Showing
9 changed files
with
255 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../ERC20Helper.sol"; | ||
import "./WhiteListHelper.sol"; | ||
|
||
abstract contract FeeBaseHelper is ERC20Helper, WhiteListHelper { | ||
event TransferInETH(uint Amount, address From); | ||
event NewFeeAmount(uint NewFeeAmount, uint OldFeeAmount); | ||
event NewFeeToken(address NewFeeToken, address OldFeeToken); | ||
|
||
error NotEnoughFeeProvided(); | ||
error FeeAmountIsZero(); | ||
error TransferFailed(); | ||
|
||
uint public FeeAmount; | ||
address public FeeToken; | ||
|
||
mapping(address => uint) public FeeReserve; | ||
|
||
function TakeFee() internal virtual firewallProtected returns(uint feeToPay){ | ||
feeToPay = FeeAmount; | ||
if(feeToPay == 0) return 0; | ||
uint credits = getCredits(msg.sender); | ||
if(credits > 0) { | ||
_whiteListRegister(msg.sender, credits < feeToPay ? credits : feeToPay); | ||
if(credits < feeToPay) { | ||
feeToPay -= credits; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
_TakeFee(feeToPay); | ||
} | ||
|
||
function _TakeFee(uint _fee) private { | ||
address _feeToken = FeeToken; // cache storage reads | ||
if (_feeToken == address(0)) { | ||
if (msg.value < _fee) revert NotEnoughFeeProvided(); | ||
emit TransferInETH(msg.value, msg.sender); | ||
} else { | ||
TransferInToken(_feeToken, msg.sender, _fee); | ||
} | ||
FeeReserve[_feeToken] += _fee; | ||
} | ||
|
||
function setFee(address _token, uint _amount) external firewallProtected onlyOwnerOrGov { | ||
FeeToken = _token; | ||
FeeAmount = _amount; | ||
} | ||
|
||
function WithdrawFee(address _token, address _to) external firewallProtected onlyOwnerOrGov { | ||
if (FeeReserve[_token] == 0) revert FeeAmountIsZero(); | ||
uint feeAmount = FeeReserve[_token]; | ||
FeeReserve[_token] = 0; | ||
if (_token == address(0)) { | ||
(bool success, ) = _to.call{value: feeAmount}(""); | ||
if (!success) revert TransferFailed(); | ||
} else { | ||
TransferToken(_token, _to, feeAmount); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../interfaces/IWhiteList.sol"; | ||
import "../GovManager.sol"; | ||
|
||
abstract contract WhiteListHelper is GovManager { | ||
error WhiteListNotSet(); | ||
|
||
uint public WhiteListId; | ||
address public WhiteListAddress; | ||
|
||
modifier WhiteListSet { | ||
if(WhiteListAddress == address(0) || WhiteListId == 0) revert WhiteListNotSet(); | ||
_; | ||
} | ||
|
||
function getCredits(address _user) public view returns(uint) { | ||
if(WhiteListAddress == address(0) || WhiteListId == 0) return 0; | ||
return IWhiteList(WhiteListAddress).Check(_user, WhiteListId); | ||
} | ||
|
||
function setupNewWhitelist(address _whiteListAddress) external firewallProtected onlyOwnerOrGov { | ||
WhiteListAddress = _whiteListAddress; | ||
WhiteListId = IWhiteList(_whiteListAddress).CreateManualWhiteList(type(uint256).max, address(this)); | ||
} | ||
|
||
function addUsers(address[] calldata _users, uint256[] calldata _credits) external firewallProtected onlyOwnerOrGov WhiteListSet { | ||
IWhiteList(WhiteListAddress).AddAddress(WhiteListId, _users, _credits); | ||
} | ||
|
||
function removeUsers(address[] calldata _users) external firewallProtected onlyOwnerOrGov WhiteListSet { | ||
IWhiteList(WhiteListAddress).RemoveAddress(WhiteListId, _users); | ||
} | ||
|
||
function _whiteListRegister(address _user, uint _credits) internal { | ||
IWhiteList(WhiteListAddress).Register(_user, WhiteListId, _credits); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../GovManager.sol"; | ||
import "../FeeBaseHelper.sol"; | ||
import "../Fee/FeeBaseHelper.sol"; | ||
|
||
// example to use FeeBaseHelper | ||
contract FeeHelper is GovManager, ERC20Helper { | ||
FeeBaseHelper public BaseFee; | ||
contract FeeHelper is FeeBaseHelper { | ||
|
||
constructor() { | ||
BaseFee = new FeeBaseHelper(); | ||
} | ||
|
||
function PayFee() public payable { | ||
if (BaseFee.FeeToken() != address(0)) { | ||
TransferInToken(BaseFee.FeeToken(), msg.sender, BaseFee.Fee()); | ||
IERC20(BaseFee.FeeToken()).approve(address(BaseFee), BaseFee.Fee()); | ||
} | ||
BaseFee.PayFee{value: msg.value}(BaseFee.Fee()); | ||
} | ||
|
||
function WithdrawFee(address payable _to) public onlyOwnerOrGov { | ||
BaseFee.WithdrawFee(BaseFee.FeeToken(), _to); | ||
} | ||
|
||
function SetFee(uint256 _amount) public onlyOwnerOrGov { | ||
BaseFee.SetFeeAmount(_amount); | ||
} | ||
|
||
function SetToken(address _token) public onlyOwnerOrGov { | ||
BaseFee.SetFeeToken(_token); | ||
function MethodWithFee() public payable returns(uint){ | ||
return TakeFee(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../interfaces/IWhiteList.sol"; | ||
|
||
contract WhiteListMock is IWhiteList { | ||
uint public WhiteListId; | ||
|
||
mapping (address => uint) public AddressToCredits; | ||
|
||
function CreateManualWhiteList(uint, address) external payable returns(uint) { | ||
return ++WhiteListId; | ||
} | ||
|
||
function Check(address _user, uint _whiteListId) external view returns(uint) { | ||
if(_whiteListId != WhiteListId) return 0; | ||
return AddressToCredits[_user]; | ||
} | ||
|
||
function Register(address _user, uint _whiteListId, uint _amount) external { | ||
if(_whiteListId != WhiteListId) return; | ||
AddressToCredits[_user] = AddressToCredits[_user] - _amount; | ||
} | ||
|
||
function AddAddress(uint256 , address[] calldata _Users, uint256[] calldata _Amount) external{ | ||
for(uint i = 0; i < _Users.length; i++){ | ||
AddressToCredits[_Users[i]] = _Amount[i]; | ||
} | ||
} | ||
|
||
function RemoveAddress(uint256 , address[] calldata _Users) external{ | ||
for(uint i = 0; i < _Users.length; i++){ | ||
delete AddressToCredits[_Users[i]]; | ||
} | ||
} | ||
|
||
// to avoid the error: Contract "WhiteListMock" should be marked as abstract | ||
function LastRoundRegister(address _Subject,uint256 _Id) external {} | ||
function ChangeCreator(uint256 _Id, address _NewCreator) external {} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.