This repository was archived by the owner on Mar 18, 2026. It is now read-only.
forked from CMTA/CMTAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathERC20BaseModule.sol
More file actions
91 lines (79 loc) · 2.84 KB
/
ERC20BaseModule.sol
File metadata and controls
91 lines (79 loc) · 2.84 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
//SPDX-License-Identifier: MPL-2.0
pragma solidity 0.8.17;
// required OZ imports here
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import "../../../libraries/Errors.sol";
abstract contract ERC20BaseModule is ERC20Upgradeable {
/* Events */
event Spend(address indexed owner, address indexed spender, uint256 amount);
/* Variables */
uint8 private _decimals;
/* Initializers */
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20Module_init(
string memory name_,
string memory symbol_,
uint8 decimals_
) internal onlyInitializing {
/* OpenZeppelin */
__Context_init_unchained();
__ERC20_init(name_, symbol_);
/* own function */
__ERC20Module_init_unchained(decimals_);
}
function __ERC20Module_init_unchained(
uint8 decimals_
) internal onlyInitializing {
_decimals = decimals_;
}
/* Methods */
/**
* @notice Returns the number of decimals used to get its user representation.
* @dev
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
bool result = super.transferFrom(sender, recipient, amount);
// The result will be normally always true because OpenZeppelin uses require to check all the conditions.
if (result) {
emit Spend(sender, _msgSender(), amount);
}
return result;
}
uint256[50] private __gap;
}