1
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
2
pragma solidity 0.6.12 ;
3
3
4
- import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol " ;
5
- import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol " ;
6
- import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol " ;
4
+ import {
5
+ SafeMathUpgradeable
6
+ } from "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol " ;
7
+ import {
8
+ IERC20Upgradeable
9
+ } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol " ;
10
+ import {
11
+ OwnableUpgradeable
12
+ } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol " ;
7
13
8
14
/**
9
15
* @title XC(cross-chain)Ample ERC20 token
@@ -15,9 +21,9 @@ import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
15
21
* Additionally, the XCAmple contract lets the XCAmpleController
16
22
* `mint` or `burn` tokens.
17
23
*/
18
- contract XCAmple is IERC20 , OwnableUpgradeSafe {
24
+ contract XCAmple is IERC20Upgradeable , OwnableUpgradeable {
19
25
// PLEASE EXERCISE CAUTION BEFORE CHANGING ANY ACCOUNTING OR MATH
20
- using SafeMath for uint256 ;
26
+ using SafeMathUpgradeable for uint256 ;
21
27
22
28
event LogRebase (uint256 indexed epoch , uint256 globalAMPLSupply );
23
29
event ControllerUpdated (address controller );
@@ -80,6 +86,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
80
86
81
87
/**
82
88
* @dev XCAmpleController notifies this contract about a new rebase cycle.
89
+ * @param epoch The rebase epoch number.
83
90
* @param newGlobalAMPLSupply The new total supply of AMPL from the base chain.
84
91
* @return The new total AMPL supply.
85
92
*/
@@ -128,15 +135,15 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
128
135
/**
129
136
* @dev Returns the name of the token.
130
137
*/
131
- function name () public view returns (string memory ) {
138
+ function name () external view returns (string memory ) {
132
139
return _name;
133
140
}
134
141
135
142
/**
136
143
* @dev Returns the symbol of the token, usually a shorter version of the
137
144
* name.
138
145
*/
139
- function symbol () public view returns (string memory ) {
146
+ function symbol () external view returns (string memory ) {
140
147
return _symbol;
141
148
}
142
149
@@ -149,22 +156,22 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
149
156
* no way affects any of the arithmetic of the contract, including
150
157
* {IERC20-balanceOf} and {IERC20-transfer}.
151
158
*/
152
- function decimals () public view returns (uint8 ) {
159
+ function decimals () external view returns (uint8 ) {
153
160
return _decimals;
154
161
}
155
162
156
163
/**
157
164
* @return The total supply of xcAmples.
158
165
*/
159
- function totalSupply () public view override returns (uint256 ) {
166
+ function totalSupply () external view override returns (uint256 ) {
160
167
return _totalSupply;
161
168
}
162
169
163
170
/**
164
171
* @param who The address to query.
165
172
* @return The balance of the specified address.
166
173
*/
167
- function balanceOf (address who ) public view override returns (uint256 ) {
174
+ function balanceOf (address who ) external view override returns (uint256 ) {
168
175
return _gonBalances[who].div (_gonsPerAMPL);
169
176
}
170
177
@@ -174,7 +181,12 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
174
181
* @param value The amount to be transferred.
175
182
* @return True on success, false otherwise.
176
183
*/
177
- function transfer (address to , uint256 value ) public override validRecipient (to) returns (bool ) {
184
+ function transfer (address to , uint256 value )
185
+ external
186
+ override
187
+ validRecipient (to)
188
+ returns (bool )
189
+ {
178
190
uint256 gonValue = value.mul (_gonsPerAMPL);
179
191
_gonBalances[msg .sender ] = _gonBalances[msg .sender ].sub (gonValue);
180
192
_gonBalances[to] = _gonBalances[to].add (gonValue);
@@ -188,7 +200,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
188
200
* @param spender The address which will spend the funds.
189
201
* @return The number of tokens still available for the spender.
190
202
*/
191
- function allowance (address owner_ , address spender ) public view override returns (uint256 ) {
203
+ function allowance (address owner_ , address spender ) external view override returns (uint256 ) {
192
204
return _allowedXCAmples[owner_][spender];
193
205
}
194
206
@@ -202,7 +214,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
202
214
address from ,
203
215
address to ,
204
216
uint256 value
205
- ) public override validRecipient (to) returns (bool ) {
217
+ ) external override validRecipient (to) returns (bool ) {
206
218
_allowedXCAmples[from][msg .sender ] = _allowedXCAmples[from][msg .sender ].sub (value);
207
219
208
220
uint256 gonValue = value.mul (_gonsPerAMPL);
@@ -224,7 +236,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
224
236
* @param spender The address which will spend the funds.
225
237
* @param value The amount of tokens to be spent.
226
238
*/
227
- function approve (address spender , uint256 value ) public override returns (bool ) {
239
+ function approve (address spender , uint256 value ) external override returns (bool ) {
228
240
_allowedXCAmples[msg .sender ][spender] = value;
229
241
emit Approval (msg .sender , spender, value);
230
242
return true ;
@@ -237,7 +249,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
237
249
* @param spender The address which will spend the funds.
238
250
* @param addedValue The amount of tokens to increase the allowance by.
239
251
*/
240
- function increaseAllowance (address spender , uint256 addedValue ) public returns (bool ) {
252
+ function increaseAllowance (address spender , uint256 addedValue ) external returns (bool ) {
241
253
_allowedXCAmples[msg .sender ][spender] = _allowedXCAmples[msg .sender ][spender].add (
242
254
addedValue
243
255
);
@@ -251,7 +263,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
251
263
* @param spender The address which will spend the funds.
252
264
* @param subtractedValue The amount of tokens to decrease the allowance by.
253
265
*/
254
- function decreaseAllowance (address spender , uint256 subtractedValue ) public returns (bool ) {
266
+ function decreaseAllowance (address spender , uint256 subtractedValue ) external returns (bool ) {
255
267
uint256 oldValue = _allowedXCAmples[msg .sender ][spender];
256
268
if (subtractedValue >= oldValue) {
257
269
_allowedXCAmples[msg .sender ][spender] = 0 ;
@@ -268,7 +280,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
268
280
* @param who The address of the beneficiary.
269
281
* @param xcAmpleAmount The amount of xcAmple tokens to be minted.
270
282
*/
271
- function mint (address who , uint256 xcAmpleAmount ) public onlyController validRecipient (who) {
283
+ function mint (address who , uint256 xcAmpleAmount ) external onlyController validRecipient (who) {
272
284
uint256 gonValue = xcAmpleAmount.mul (_gonsPerAMPL);
273
285
_gonBalances[who] = _gonBalances[who].add (gonValue);
274
286
_totalSupply = _totalSupply.add (xcAmpleAmount);
@@ -285,7 +297,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
285
297
* @param who The address of the beneficiary.
286
298
* @param xcAmpleAmount The amount of xcAmple tokens to be burned.
287
299
*/
288
- function burn (address who , uint256 xcAmpleAmount ) public onlyController {
300
+ function burn (address who , uint256 xcAmpleAmount ) external onlyController {
289
301
require (who != address (0 ), "XCAmple: burn address zero address " );
290
302
291
303
uint256 gonValue = xcAmpleAmount.mul (_gonsPerAMPL);
0 commit comments