-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGladiatorReceiver.sol
161 lines (140 loc) · 5.77 KB
/
GladiatorReceiver.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
/*
.:=::.
-+*#%%%@+-==+++-.
=*%%@@%%%@@= :*%%-.-+=.
.+@@@@@@@%@+#@@%*+ :@+:.
:#@@@@*@@%@@@@@#@@@.=@ .@#-==:
=#@@@@@%*@@@@@@@#@@+.=* %%@@@%#+
+#*%@@@##@@@@@@#@@=-#.#%%@@=
.%#@=%@@@+@*@@@@#@%@+@*##@# :%
%@%+@=%@@*++@@@#@%:++@*%-@=*@@
%%@@@+#%@@=%@@@#@%*+@+#*-#%@*%
.@%@%%@@%+%%:%%@##+:%*=%@@%%@*@.
-@@@. .:-++=%@%*--++==:. .@
-@%@: **+*. .%-+:
=#@#+=-: ++ :--+*-+.
=@%@*#%@. .@%#*#+ .
=@@@*+#+. @%*#* :
#@%%%*++- =*+#= :-*
+@#@#=##=*+ #*+#*:--.@*
+@*@*-=# +- -+.#=-*+-@*
:%#= .@.:+ +-:@. =#%-
-#*-@- # #==@:*#-
.=#%*@ @*%*=.
:- --
Brokenreality
Gladiator Funds Receiver
*/
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
// Error Library
error TokenNotAllowed();
error EthTransferFailed();
error ZeroValue();
/// @title Gladitor Funds Receviable Contract
/// @dev This contract is strictly used to receive developer funds for the Gladitor project
contract GladiatorReceiver is Ownable, ReentrancyGuard {
// Mental Health Foundation (part of my story)
address payable public mhf;
// Animal Sanctuary
address payable public asanc;
// CROC (Citizens Reunited to Overcome Cancer)
address payable public croc;
// developer fund
address payable public devFund;
// Allowed ERC20 token list
mapping(address => bool) public allowedTokens;
// Event emitters
event Deposit(address account, address token, uint256 amount);
// Set default developer fund address
constructor(address _mhf, address _asanc, address _croc, address _devFund) {
mhf = payable(_mhf);
asanc = payable(_asanc);
croc = payable(_croc);
devFund = payable(_devFund);
}
receive() external payable {}
/**
** @dev The allowAddress function updates the list of accepted
** tokens managed by the contract.
** @param _token The ERC20 token address to allow
*/
function allowAddress(address _token) public onlyOwner {
allowedTokens[_token] = true;
}
/**
** @dev The deposit function accepts a token address merely for emission
** purposes. The token address will be checked against the allow list.
** Additionally the token allowance will also be checked.
** @param _token The ERC20 token address to be deposited
** @param _amount The ERC20 amount to be deposited
*/
function deposit(address _token, uint _amount) public payable nonReentrant {
if (_amount == 0) revert ZeroValue();
if (!allowedTokens[_token]) revert TokenNotAllowed();
bool success = IERC20(_token).transferFrom(msg.sender, address(this), _amount);
if (!success) revert EthTransferFailed();
emit Deposit(msg.sender, _token, _amount);
}
/**
** @dev The withdraw function checks the current contract balance of the passed ERC20 token
** and performs a withdraw using the tried and true call method.
*/
function withdraw(address _token) external onlyOwner nonReentrant {
uint256 currentBalance = IERC20(_token).balanceOf(address(this));
if (currentBalance == 0) revert ZeroValue();
bool success = IERC20(_token).transfer(devFund, currentBalance);
if (!success) revert EthTransferFailed();
}
/**
** @dev The withdraw function checks the current contract balance of ETH
** and performs a withdraw using the tried and true call method.
*/
function withdrawEth() external onlyOwner nonReentrant {
uint256 currentBalance = address(this).balance;
if (currentBalance == 0) revert ZeroValue();
uint256 amountToTransfer = (currentBalance * 25e19) / 1e21;
(bool success1, ) = payable(mhf).call{value: amountToTransfer}("");
if (!success1) revert EthTransferFailed();
(bool success2, ) = payable(asanc).call{value: amountToTransfer}("");
if (!success2) revert EthTransferFailed();
(bool success3, ) = payable(croc).call{value: amountToTransfer}("");
if (!success3) revert EthTransferFailed();
(bool success4, ) = payable(devFund).call{value: amountToTransfer}("");
if (!success4) revert EthTransferFailed();
}
function balanceOfToken(address _token) public view returns (uint256) {
return IERC20(_token).balanceOf(address(this));
}
/**
** @dev The setMhfAccount function updates the address in which
** the funds can be withdrawn to Mental Health Foundation.
*/
function setMhfAccount(address _mhf) external onlyOwner {
mhf = payable(_mhf);
}
/**
** @dev The setAsancAccount function updates the address in which
** the funds can be withdrawn to the Animal Sanctuary.
*/
function setAsancAccount(address _asanc) external onlyOwner {
asanc = payable(_asanc);
}
/**
** @dev The setCrocAccount function updates the address in which
** the funds can be withdrawn to CROC.
*/
function setCrocAccount(address _croc) external onlyOwner {
croc = payable(_croc);
}
/**
** @dev The setDeveloperFund function updates the address in which
** the funds can be withdrawn to the developer fund.
*/
function setDevAccount(address _devFund) external onlyOwner {
devFund = payable(_devFund);
}
}