Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update naming #108

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions contracts/ERC20Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,50 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@ironblocks/firewall-consumer/contracts/FirewallConsumer.sol";

contract ERC20Helper is FirewallConsumer {
event TransferOut(uint256 Amount, address To, address Token);
event TransferIn(uint256 Amount, address From, address Token);
event TransferOut(uint256 amount, address to, IERC20 token);
event TransferIn(uint256 amount, address from, IERC20 token);

error NoAllowance();
error SentIncorrectAmount();
error ReceivedIncorrectAmount();
error ZeroAmount();

modifier TestAllowance(
address _token,
address _owner,
uint256 _amount
modifier testAllowance(
IERC20 token,
address owner,
uint256 amount
) {
if (ERC20(_token).allowance(_owner, address(this)) < _amount) {
if (token.allowance(owner, address(this)) < amount) {
revert NoAllowance();
}
_;
}

function TransferToken(
address _Token,
address _Reciver,
uint256 _Amount
) internal firewallProtectedSig(0x3844b707) {
uint256 OldBalance = ERC20(_Token).balanceOf(address(this));
emit TransferOut(_Amount, _Reciver, _Token);
ERC20(_Token).transfer(_Reciver, _Amount);
if (ERC20(_Token).balanceOf(address(this)) == (OldBalance + _Amount)) revert SentIncorrectAmount();
function transferToken(IERC20 token, address receiver, uint256 amount) internal firewallProtectedSig(0x3844b707) {
uint256 oldBalance = token.balanceOf(address(this));
emit TransferOut(amount, receiver, token);
token.transfer(receiver, amount);
if (token.balanceOf(address(this)) == (oldBalance + amount)) revert SentIncorrectAmount();
}

function TransferInToken(
address _Token,
address _Subject,
uint256 _Amount
) internal TestAllowance(_Token, _Subject, _Amount) {
if (_Amount == 0) revert ZeroAmount();
uint256 OldBalance = ERC20(_Token).balanceOf(address(this));
ERC20(_Token).transferFrom(_Subject, address(this), _Amount);
emit TransferIn(_Amount, _Subject, _Token);
if (ERC20(_Token).balanceOf(address(this)) != (OldBalance + _Amount)) revert ReceivedIncorrectAmount();
function transferInToken(
IERC20 token,
address subject,
uint256 amount
) internal testAllowance(token, subject, amount) {
if (amount == 0) revert ZeroAmount();
uint256 oldBalance = token.balanceOf(address(this));
token.transferFrom(subject, address(this), amount);
emit TransferIn(amount, subject, token);
if (token.balanceOf(address(this)) != (oldBalance + amount)) revert ReceivedIncorrectAmount();
}

function ApproveAllowanceERC20(
address _Token,
address _Subject,
uint256 _Amount
function approveAllowanceERC20(
IERC20 token,
address subject,
uint256 amount
) internal firewallProtectedSig(0x91251680) {
if (_Amount == 0) revert ZeroAmount();
ERC20(_Token).approve(_Subject, _Amount);
if (amount == 0) revert ZeroAmount();
token.approve(subject, amount);
}
}
45 changes: 21 additions & 24 deletions contracts/ERC721Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,39 @@ import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@ironblocks/firewall-consumer/contracts/FirewallConsumer.sol";

contract ERC721Helper is FirewallConsumer {
event TransferOut(address Token, uint256 TokenId, address To);
event TransferIn(address Token, uint256 TokenId, address From);
event TransferOut(IERC721 token, uint256 tokenId, address to);
event TransferIn(IERC721 token, uint256 tokenId, address from);

error NoAllowance();

modifier TestNFTAllowance(
address _token,
uint256 _tokenId,
address _owner
modifier testNFTAllowance(
IERC721 token,
uint256 tokenId,
address owner
) {
if (
!IERC721(_token).isApprovedForAll(_owner, address(this)) &&
IERC721(_token).getApproved(_tokenId) != address(this)
) {
if (!token.isApprovedForAll(owner, address(this)) && token.getApproved(tokenId) != address(this)) {
revert NoAllowance();
}
_;
}

function TransferNFTOut(address _Token, uint256 _TokenId, address _To) internal firewallProtectedSig(0x53905fab) {
IERC721(_Token).transferFrom(address(this), _To, _TokenId);
emit TransferOut(_Token, _TokenId, _To);
assert(IERC721(_Token).ownerOf(_TokenId) == _To);
function transferNFTOut(IERC721 token, uint256 tokenId, address to) internal firewallProtectedSig(0x53905fab) {
token.transferFrom(address(this), to, tokenId);
emit TransferOut(token, tokenId, to);
assert(token.ownerOf(tokenId) == to);
}

function TransferNFTIn(
address _Token,
uint256 _TokenId,
address _From
) internal TestNFTAllowance(_Token, _TokenId, _From) {
IERC721(_Token).transferFrom(_From, address(this), _TokenId);
emit TransferOut(_Token, _TokenId, _From);
assert(IERC721(_Token).ownerOf(_TokenId) == address(this));
function transferNFTIn(
IERC721 token,
uint256 tokenId,
address from
) internal testNFTAllowance(token, tokenId, from) {
token.transferFrom(from, address(this), tokenId);
emit TransferOut(token, tokenId, from);
assert(token.ownerOf(tokenId) == address(this));
}

function SetApproveForAllNFT(address _Token, address _To, bool _Approve) internal firewallProtectedSig(0xd5ebe78c) {
IERC721(_Token).setApprovalForAll(_To, _Approve);
function setApproveForAllNFT(IERC721 token, address to, bool approve) internal firewallProtectedSig(0xd5ebe78c) {
token.setApprovalForAll(to, approve);
}
}
32 changes: 16 additions & 16 deletions contracts/ETHHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@ironblocks/firewall-consumer/contracts/FirewallConsumer.sol";

contract ETHHelper is Ownable, FirewallConsumer {
constructor() Ownable(_msgSender()) {}

error InvalidAmount();
error SentIncorrectAmount();

constructor() Ownable(_msgSender()) {}

modifier ReceivETH(
modifier receivETH(
uint256 msgValue,
address msgSender,
uint256 _MinETHInvest
uint256 minETHInvest
) {
if (msgValue < _MinETHInvest) revert InvalidAmount();
if (msgValue < minETHInvest) revert InvalidAmount();
emit TransferInETH(msgValue, msgSender);
_;
}

//@dev not/allow contract to receive funds
receive() external payable {
if (!IsPayble) revert();
if (!isPayble) revert();
}

event TransferOutETH(uint256 Amount, address To);
event TransferInETH(uint256 Amount, address From);
event TransferOutETH(uint256 amount, address to);
event TransferInETH(uint256 amount, address from);

bool public IsPayble;
bool public isPayble;

function SwitchIsPayble() public onlyOwner {
IsPayble = !IsPayble;
function switchIsPayble() public onlyOwner {
isPayble = !isPayble;
}

function TransferETH(address payable _Reciver, uint256 _amount) internal firewallProtectedSig(0xfd69c215) {
emit TransferOutETH(_amount, _Reciver);
uint256 beforeBalance = address(_Reciver).balance;
_Reciver.transfer(_amount);
if ((beforeBalance + _amount) != address(_Reciver).balance) revert SentIncorrectAmount();
function transferETH(address payable receiver, uint256 _amount) internal firewallProtectedSig(0xfd69c215) {
emit TransferOutETH(_amount, receiver);
uint256 beforeBalance = address(receiver).balance;
receiver.transfer(_amount);
if ((beforeBalance + _amount) != address(receiver).balance) revert SentIncorrectAmount();
}
}
52 changes: 26 additions & 26 deletions contracts/Fee/FeeBaseHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,59 @@ 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);
event TransferInETH(uint256 amount, address from);
event NewFeeAmount(uint256 newFeeAmount, uint256 oldFeeAmount);
event NewFeeToken(address newFeeToken, address oldFeeToken);

error NotEnoughFeeProvided();
error FeeAmountIsZero();
error TransferFailed();

uint public FeeAmount;
address public FeeToken;

mapping(address => uint) public FeeReserve;
uint256 public feeAmount;
address public feeToken;

function TakeFee() internal virtual firewallProtected returns(uint feeToPay){
feeToPay = FeeAmount;
if(feeToPay == 0) return 0;
uint credits = getCredits(msg.sender);
if(credits > 0) {
mapping(address => uint256) public feeReserve;

function takeFee() internal virtual firewallProtected returns (uint256 feeToPay) {
feeToPay = feeAmount;
if (feeToPay == 0) return 0;
uint256 credits = getCredits(msg.sender);
if (credits > 0) {
_whiteListRegister(msg.sender, credits < feeToPay ? credits : feeToPay);
if(credits < feeToPay) {
if (credits < feeToPay) {
feeToPay -= credits;
} else {
return 0;
}
}
_TakeFee(feeToPay);
_takeFee(feeToPay);
}

function _TakeFee(uint _fee) private {
address _feeToken = FeeToken; // cache storage reads
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);
transferInToken(IERC20(_feeToken), msg.sender, _fee);
}
FeeReserve[_feeToken] += _fee;
feeReserve[_feeToken] += _fee;
}

function setFee(address _token, uint _amount) external firewallProtected onlyOwnerOrGov {
FeeToken = _token;
FeeAmount = _amount;
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;
function withdrawFee(address _token, address _to) external firewallProtected onlyOwnerOrGov {
if (feeReserve[_token] == 0) revert FeeAmountIsZero();
uint256 amount = feeReserve[_token];
feeReserve[_token] = 0;
if (_token == address(0)) {
(bool success, ) = _to.call{value: feeAmount}("");
(bool success, ) = _to.call{value: amount}("");
if (!success) revert TransferFailed();
} else {
TransferToken(_token, _to, feeAmount);
transferToken(IERC20(_token), _to, amount);
}
}
}
33 changes: 18 additions & 15 deletions contracts/Fee/WhiteListHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,36 @@ import "../GovManager.sol";
abstract contract WhiteListHelper is GovManager {
error WhiteListNotSet();

uint public WhiteListId;
address public WhiteListAddress;
uint public whiteListId;
address public whiteListAddress;

modifier WhiteListSet {
if(WhiteListAddress == address(0) || WhiteListId == 0) revert WhiteListNotSet();
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 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));
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 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 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);
IWhiteList(whiteListAddress).Register(_user, whiteListId, _credits);
}
}
}
14 changes: 6 additions & 8 deletions contracts/GovManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ contract GovManager is Ownable, FirewallConsumer {

error AuthorizationError();

address public GovernorContract;
address public governorContract;

modifier onlyOwnerOrGov() {
if (msg.sender != owner() && msg.sender != GovernorContract) {
if (msg.sender != owner() && msg.sender != governorContract) {
revert AuthorizationError();
}
_;
}

function setGovernorContract(address _address) external firewallProtected onlyOwnerOrGov {
address oldGov = GovernorContract;
GovernorContract = _address;
emit GovernorUpdated(oldGov, GovernorContract);
address oldGov = governorContract;
governorContract = _address;
emit GovernorUpdated(oldGov, governorContract);
}

constructor() Ownable(_msgSender()) {
GovernorContract = address(0);
}
constructor() Ownable(_msgSender()) {}
}
Loading