-
Notifications
You must be signed in to change notification settings - Fork 3
/
WeSenditToken.sol
151 lines (134 loc) · 4.08 KB
/
WeSenditToken.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "./BaseWeSenditToken.sol";
/**
* @title WeSendit ERC20 token
*/
contract WeSenditToken is BaseWeSenditToken, ERC20Capped, ERC20Burnable {
constructor(address addressTotalSupply)
ERC20("WeSendit", "WSI")
ERC20Capped(TOTAL_SUPPLY)
BaseWeSenditToken()
{
_mint(addressTotalSupply, TOTAL_SUPPLY);
}
/**
* Transfer token from without fee reflection
*
* @param from address - Address to transfer token from
* @param to address - Address to transfer token to
* @param amount uint256 - Amount of token to transfer
*
* @return bool - Indicator if transfer was successful
*/
function transferFromNoFees(
address from,
address to,
uint256 amount
) external virtual override returns (bool) {
require(
_msgSender() == address(dynamicFeeManager()),
"WeSendit: Can only be called by Dynamic Fee Manager"
);
return super.transferFrom(from, to, amount);
}
/**
* Transfer token with fee reflection
*
* @inheritdoc ERC20
*/
function transfer(address to, uint256 amount)
public
virtual
override
returns (bool)
{
// Reflect fees
(uint256 tTotal, ) = _reflectFees(_msgSender(), to, amount);
// Execute normal transfer
return super.transfer(to, tTotal);
}
/**
* Transfer token from with fee reflection
*
* @inheritdoc ERC20
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
// Reflect fees
(uint256 tTotal, ) = _reflectFees(from, to, amount);
// Execute normal transfer
return super.transferFrom(from, to, tTotal);
}
/**
* @inheritdoc ERC20
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
_preValidateTransfer(from);
}
// Needed since we inherit from ERC20 and ERC20Capped
function _mint(address account, uint256 amount)
internal
virtual
override(ERC20, ERC20Capped)
{
super._mint(account, amount);
}
/**
* Reflects fees using the dynamic fee manager
*
* @param from address - Sender address
* @param to address - Receiver address
* @param amount uint256 - Transaction amount
*/
function _reflectFees(
address from,
address to,
uint256 amount
) private returns (uint256 tTotal, uint256 tFees) {
if (address(dynamicFeeManager()) == address(0)) {
return (amount, 0);
} else {
// Allow dynamic fee manager to spent amount for fees if needed
_approve(from, address(dynamicFeeManager()), amount);
// Reflect fees
(tTotal, tFees) = dynamicFeeManager().reflectFees(from, to, amount);
// Reset fee manager approval to zero for security reason
_approve(from, address(dynamicFeeManager()), 0);
return (tTotal, tFees);
}
}
/**
* Checks if the minimum transaction amount is exceeded and if pause is enabled
*
* @param from address - Sender address
*/
function _preValidateTransfer(address from) private view {
/**
* Only allow transfers if:
* - token is not paused
* - sender is owner
* - sender is admin
* - sender has bypass role
*/
require(
!paused() ||
from == address(0) ||
from == owner() ||
hasRole(ADMIN, from) ||
hasRole(BYPASS_PAUSE, from),
"WeSendit: transactions are paused"
);
}
}