-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTaxOfficeV2.sol
More file actions
186 lines (154 loc) · 6.02 KB
/
TaxOfficeV2.sol
File metadata and controls
186 lines (154 loc) · 6.02 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./owner/Operator.sol";
import "./interfaces/ITaxable.sol";
import "./interfaces/IUniswapV2Router.sol";
import "./interfaces/IERC20.sol";
contract TaxOfficeV2 is Operator {
using SafeMath for uint256;
address public grape = address(0x522348779DCb2911539e76A1042aA922F9C47Ee3);
address public weth = address(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
address public uniRouter = address(0x10ED43C718714eb63d5aA57B78B54704E256024E);
mapping(address => bool) public taxExclusionEnabled;
function setTaxTiersTwap(uint8 _index, uint256 _value) public onlyOperator returns (bool) {
return ITaxable(grape).setTaxTiersTwap(_index, _value);
}
function setTaxTiersRate(uint8 _index, uint256 _value) public onlyOperator returns (bool) {
return ITaxable(grape).setTaxTiersRate(_index, _value);
}
function enableAutoCalculateTax() public onlyOperator {
ITaxable(grape).enableAutoCalculateTax();
}
function disableAutoCalculateTax() public onlyOperator {
ITaxable(grape).disableAutoCalculateTax();
}
function setTaxRate(uint256 _taxRate) public onlyOperator {
ITaxable(grape).setTaxRate(_taxRate);
}
function setBurnThreshold(uint256 _burnThreshold) public onlyOperator {
ITaxable(grape).setBurnThreshold(_burnThreshold);
}
function setTaxCollectorAddress(address _taxCollectorAddress) public onlyOperator {
ITaxable(grape).setTaxCollectorAddress(_taxCollectorAddress);
}
function excludeAddressFromTax(address _address) external onlyOperator returns (bool) {
return _excludeAddressFromTax(_address);
}
function _excludeAddressFromTax(address _address) private returns (bool) {
if (!ITaxable(grape).isAddressExcluded(_address)) {
return ITaxable(grape).excludeAddress(_address);
}
}
function includeAddressInTax(address _address) external onlyOperator returns (bool) {
return _includeAddressInTax(_address);
}
function _includeAddressInTax(address _address) private returns (bool) {
if (ITaxable(grape).isAddressExcluded(_address)) {
return ITaxable(grape).includeAddress(_address);
}
}
function taxRate() external returns (uint256) {
return ITaxable(grape).taxRate();
}
function addLiquidityTaxFree(
address token,
uint256 amtGrape,
uint256 amtToken,
uint256 amtGrapeMin,
uint256 amtTokenMin
)
external
returns (
uint256,
uint256,
uint256
)
{
require(amtGrape != 0 && amtToken != 0, "amounts can't be 0");
_excludeAddressFromTax(msg.sender);
IERC20(grape).transferFrom(msg.sender, address(this), amtGrape);
IERC20(token).transferFrom(msg.sender, address(this), amtToken);
_approveTokenIfNeeded(grape, uniRouter);
_approveTokenIfNeeded(token, uniRouter);
_includeAddressInTax(msg.sender);
uint256 resultAmtGrape;
uint256 resultAmtToken;
uint256 liquidity;
(resultAmtGrape, resultAmtToken, liquidity) = IUniswapV2Router(uniRouter).addLiquidity(
grape,
token,
amtGrape,
amtToken,
amtGrapeMin,
amtTokenMin,
msg.sender,
block.timestamp
);
if (amtGrape.sub(resultAmtGrape) > 0) {
IERC20(grape).transfer(msg.sender, amtGrape.sub(resultAmtGrape));
}
if (amtToken.sub(resultAmtToken) > 0) {
IERC20(token).transfer(msg.sender, amtToken.sub(resultAmtToken));
}
return (resultAmtGrape, resultAmtToken, liquidity);
}
function addLiquidityETHTaxFree(
uint256 amtGrape,
uint256 amtGrapeMin,
uint256 amtEthMin
)
external
payable
returns (
uint256,
uint256,
uint256
)
{
require(amtGrape != 0 && msg.value != 0, "amounts can't be 0");
_excludeAddressFromTax(msg.sender);
IERC20(grape).transferFrom(msg.sender, address(this), amtGrape);
_approveTokenIfNeeded(grape, uniRouter);
_includeAddressInTax(msg.sender);
uint256 resultAmtGrape;
uint256 resultAmtEth;
uint256 liquidity;
(resultAmtGrape, resultAmtEth, liquidity) = IUniswapV2Router(uniRouter).addLiquidityETH{value: msg.value}(
grape,
amtGrape,
amtGrapeMin,
amtEthMin,
msg.sender,
block.timestamp
);
if (amtGrape.sub(resultAmtGrape) > 0) {
IERC20(grape).transfer(msg.sender, amtGrape.sub(resultAmtGrape));
}
return (resultAmtGrape, resultAmtEth, liquidity);
}
function setTaxableGrapeOracle(address _grapeOracle) external onlyOperator {
ITaxable(grape).setGrapeOracle(_grapeOracle);
}
function transferTaxOffice(address _newTaxOffice) external onlyOperator {
ITaxable(grape).setTaxOffice(_newTaxOffice);
}
function taxFreeTransferFrom(
address _sender,
address _recipient,
uint256 _amt
) external {
require(taxExclusionEnabled[msg.sender], "Address not approved for tax free transfers");
_excludeAddressFromTax(_sender);
IERC20(grape).transferFrom(_sender, _recipient, _amt);
_includeAddressInTax(_sender);
}
function setTaxExclusionForAddress(address _address, bool _excluded) external onlyOperator {
taxExclusionEnabled[_address] = _excluded;
}
function _approveTokenIfNeeded(address _token, address _router) private {
if (IERC20(_token).allowance(address(this), _router) == 0) {
IERC20(_token).approve(_router, type(uint256).max);
}
}
}