-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathDependencies.sol
131 lines (110 loc) · 3.93 KB
/
Dependencies.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
// SPDX-License-Identifier: BSL-1.0 (Boost Software License 1.0)
//-------------------------------------------------------------------------------------//
// Copyright (c) 2022 - 2023 serial-coder: Phuwanai Thummavet ([email protected]) //
//-------------------------------------------------------------------------------------//
// For more info, please refer to my article:
// - On Medium: https://medium.com/valixconsulting/solidity-smart-contract-security-by-example-05-cross-contract-reentrancy-30f29e2a01b9
// - On serial-coder.com: https://www.serial-coder.com/post/solidity-smart-contract-security-by-example-05-cross-contract-reentrancy/
pragma solidity 0.8.17;
abstract contract ReentrancyGuard {
bool internal locked;
modifier noReentrant() {
require(!locked, "No re-entrancy");
locked = true;
_;
locked = false;
}
}
interface IMoonToken {
function transferOwnership(address _newOwner) external;
function transfer(address _to, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
function balanceOf(address _owner) external view returns (uint256 balance);
function approve(address _spender, uint256 _value) external returns (bool success);
function allowance(address _owner, address _spender) external view returns (uint256 remaining);
function mint(address _to, uint256 _value) external returns (bool success);
function burnAccount(address _from) external returns (bool success);
}
contract MoonToken {
uint256 private constant MAX_UINT256 = type(uint256).max;
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;
string public constant name = "MOON Token";
string public constant symbol = "MOON";
uint8 public constant decimals = 18;
uint256 public totalSupply;
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(owner == msg.sender, "You are not the owner");
_;
}
function transferOwnership(address _newOwner) external onlyOwner {
owner = _newOwner;
}
function transfer(address _to, uint256 _value)
external
returns (bool success)
{
require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
return true;
}
function transferFrom(
address _from,
address _to,
uint256 _value
) external returns (bool success) {
uint256 allowance_ = allowed[_from][msg.sender];
require(balances[_from] >= _value && allowance_ >= _value);
balances[_to] += _value;
balances[_from] -= _value;
if (allowance_ < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
return true;
}
function balanceOf(address _owner)
external
view
returns (uint256 balance)
{
return balances[_owner];
}
function approve(address _spender, uint256 _value)
external
returns (bool success)
{
allowed[msg.sender][_spender] = _value;
return true;
}
function allowance(address _owner, address _spender)
external
view
returns (uint256 remaining)
{
return allowed[_owner][_spender];
}
function mint(address _to, uint256 _value)
external
onlyOwner // MoonVault must be the contract owner
returns (bool success)
{
balances[_to] += _value;
totalSupply += _value;
return true;
}
function burnAccount(address _from)
external
onlyOwner // MoonVault must be the contract owner
returns (bool success)
{
uint256 amountToBurn = balances[_from];
balances[_from] -= amountToBurn;
totalSupply -= amountToBurn;
return true;
}
}