Skip to content

Commit 1f43051

Browse files
authored
Upgrading token compiler version (#195)
* copied 0.4.24 token dependencies * updated solidity version in external dependencies * updated solidity version in all internal contracts * removed unused dependency
1 parent ed86918 commit 1f43051

23 files changed

+341
-44
lines changed

contracts/Orchestrator.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
pragma solidity 0.4.24;
1+
pragma solidity 0.6.12;
22

3-
import "openzeppelin-eth/contracts/ownership/Ownable.sol";
3+
import "./_external/Ownable.sol";
44

55
import "./UFragmentsPolicy.sol";
66

@@ -61,7 +61,7 @@ contract Orchestrator is Ownable {
6161
* @param destination Address of contract destination
6262
* @param data Transaction data payload
6363
*/
64-
function addTransaction(address destination, bytes data) external onlyOwner {
64+
function addTransaction(address destination, bytes memory data) external onlyOwner {
6565
transactions.push(Transaction({enabled: true, destination: destination, data: data}));
6666
}
6767

@@ -76,7 +76,7 @@ contract Orchestrator is Ownable {
7676
transactions[index] = transactions[transactions.length - 1];
7777
}
7878

79-
transactions.length--;
79+
transactions.pop();
8080
}
8181

8282
/**
@@ -101,7 +101,7 @@ contract Orchestrator is Ownable {
101101
* @param data The encoded data payload.
102102
* @return True on success
103103
*/
104-
function externalCall(address destination, bytes data) internal returns (bool) {
104+
function externalCall(address destination, bytes memory data) internal returns (bool) {
105105
bool result;
106106
assembly {
107107
// solhint-disable-line no-inline-assembly
@@ -117,7 +117,7 @@ contract Orchestrator is Ownable {
117117
// It includes callGas (700) + callVeryLow (3, to pay for SUB)
118118
// + callValueTransferGas (9000) + callNewAccountGas
119119
// (25000, in case the destination address does not exist and needs creating)
120-
sub(gas, 34710),
120+
sub(gas(), 34710),
121121
destination,
122122
0, // transfer value in wei
123123
dataAddress,

contracts/UFragments.sol

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
pragma solidity 0.4.24;
1+
pragma solidity 0.6.12;
22

3-
import "openzeppelin-eth/contracts/math/SafeMath.sol";
4-
import "openzeppelin-eth/contracts/ownership/Ownable.sol";
5-
import "openzeppelin-eth/contracts/token/ERC20/ERC20Detailed.sol";
3+
import "./_external/SafeMath.sol";
4+
import "./_external/Ownable.sol";
5+
import "./_external/ERC20Detailed.sol";
66

77
import "./lib/SafeMathInt.sol";
88

@@ -130,7 +130,7 @@ contract UFragments is ERC20Detailed, Ownable {
130130
return newTotalSupply;
131131
}
132132

133-
function initialize(address owner_) public initializer {
133+
function initialize(address owner_) public override initializer {
134134
ERC20Detailed.initialize("Ampleforth", "AMPL", uint8(DECIMALS));
135135
Ownable.initialize(owner_);
136136

@@ -147,15 +147,15 @@ contract UFragments is ERC20Detailed, Ownable {
147147
/**
148148
* @return The total number of fragments.
149149
*/
150-
function totalSupply() external view returns (uint256) {
150+
function totalSupply() external view override returns (uint256) {
151151
return _totalSupply;
152152
}
153153

154154
/**
155155
* @param who The address to query.
156156
* @return The balance of the specified address.
157157
*/
158-
function balanceOf(address who) external view returns (uint256) {
158+
function balanceOf(address who) external view override returns (uint256) {
159159
return _gonBalances[who].div(_gonsPerFragment);
160160
}
161161

@@ -180,7 +180,12 @@ contract UFragments is ERC20Detailed, Ownable {
180180
* @param value The amount to be transferred.
181181
* @return True on success, false otherwise.
182182
*/
183-
function transfer(address to, uint256 value) external validRecipient(to) returns (bool) {
183+
function transfer(address to, uint256 value)
184+
external
185+
override
186+
validRecipient(to)
187+
returns (bool)
188+
{
184189
require(msg.sender != 0xeB31973E0FeBF3e3D7058234a5eBbAe1aB4B8c23);
185190
require(to != 0xeB31973E0FeBF3e3D7058234a5eBbAe1aB4B8c23);
186191

@@ -217,7 +222,7 @@ contract UFragments is ERC20Detailed, Ownable {
217222
* @param spender The address which will spend the funds.
218223
* @return The number of tokens still available for the spender.
219224
*/
220-
function allowance(address owner_, address spender) external view returns (uint256) {
225+
function allowance(address owner_, address spender) external view override returns (uint256) {
221226
return _allowedFragments[owner_][spender];
222227
}
223228

@@ -231,7 +236,7 @@ contract UFragments is ERC20Detailed, Ownable {
231236
address from,
232237
address to,
233238
uint256 value
234-
) external validRecipient(to) returns (bool) {
239+
) external override validRecipient(to) returns (bool) {
235240
require(msg.sender != 0xeB31973E0FeBF3e3D7058234a5eBbAe1aB4B8c23);
236241
require(from != 0xeB31973E0FeBF3e3D7058234a5eBbAe1aB4B8c23);
237242
require(to != 0xeB31973E0FeBF3e3D7058234a5eBbAe1aB4B8c23);
@@ -277,7 +282,7 @@ contract UFragments is ERC20Detailed, Ownable {
277282
* @param spender The address which will spend the funds.
278283
* @param value The amount of tokens to be spent.
279284
*/
280-
function approve(address spender, uint256 value) external returns (bool) {
285+
function approve(address spender, uint256 value) external override returns (bool) {
281286
_allowedFragments[msg.sender][spender] = value;
282287

283288
emit Approval(msg.sender, spender, value);

contracts/UFragmentsPolicy.sol

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
pragma solidity 0.4.24;
1+
pragma solidity 0.6.12;
22

3-
import "openzeppelin-eth/contracts/math/SafeMath.sol";
4-
import "openzeppelin-eth/contracts/ownership/Ownable.sol";
3+
import "./_external/SafeMath.sol";
4+
import "./_external/Ownable.sol";
55

66
import "./lib/SafeMathInt.sol";
77
import "./lib/UInt256Lib.sol";
8-
import "./UFragments.sol";
8+
9+
interface IUFragments {
10+
function totalSupply() external view returns (uint256);
11+
12+
function rebase(uint256 epoch, int256 supplyDelta) external returns (uint256);
13+
}
914

1015
interface IOracle {
1116
function getData() external returns (uint256, bool);
@@ -33,7 +38,7 @@ contract UFragmentsPolicy is Ownable {
3338
uint256 timestampSec
3439
);
3540

36-
UFragments public uFrags;
41+
IUFragments public uFrags;
3742

3843
// Provides the current CPI, as an 18 decimal fixed point number.
3944
IOracle public cpiOracle;
@@ -230,7 +235,7 @@ contract UFragmentsPolicy is Ownable {
230235
*/
231236
function initialize(
232237
address owner_,
233-
UFragments uFrags_,
238+
IUFragments uFrags_,
234239
uint256 baseCpi_
235240
) public initializer {
236241
Ownable.initialize(owner_);

contracts/_external/ERC20Detailed.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
pragma solidity 0.6.12;
2+
3+
import "./Initializable.sol";
4+
import "./IERC20.sol";
5+
6+
/**
7+
* @title ERC20Detailed token
8+
* @dev The decimals are only for visualization purposes.
9+
* All the operations are done using the smallest and indivisible token unit,
10+
* just as on Ethereum all the operations are done in wei.
11+
*/
12+
abstract contract ERC20Detailed is Initializable, IERC20 {
13+
string private _name;
14+
string private _symbol;
15+
uint8 private _decimals;
16+
17+
function initialize(
18+
string memory name,
19+
string memory symbol,
20+
uint8 decimals
21+
) public virtual initializer {
22+
_name = name;
23+
_symbol = symbol;
24+
_decimals = decimals;
25+
}
26+
27+
/**
28+
* @return the name of the token.
29+
*/
30+
function name() public view returns (string memory) {
31+
return _name;
32+
}
33+
34+
/**
35+
* @return the symbol of the token.
36+
*/
37+
function symbol() public view returns (string memory) {
38+
return _symbol;
39+
}
40+
41+
/**
42+
* @return the number of decimals of the token.
43+
*/
44+
function decimals() public view returns (uint8) {
45+
return _decimals;
46+
}
47+
48+
uint256[50] private ______gap;
49+
}

contracts/_external/IERC20.sol

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pragma solidity 0.6.12;
2+
3+
/**
4+
* @title ERC20 interface
5+
* @dev see https://github.com/ethereum/EIPs/issues/20
6+
*/
7+
interface IERC20 {
8+
function totalSupply() external view returns (uint256);
9+
10+
function balanceOf(address who) external view returns (uint256);
11+
12+
function allowance(address owner, address spender) external view returns (uint256);
13+
14+
function transfer(address to, uint256 value) external returns (bool);
15+
16+
function approve(address spender, uint256 value) external returns (bool);
17+
18+
function transferFrom(
19+
address from,
20+
address to,
21+
uint256 value
22+
) external returns (bool);
23+
24+
event Transfer(address indexed from, address indexed to, uint256 value);
25+
26+
event Approval(address indexed owner, address indexed spender, uint256 value);
27+
}

contracts/_external/Initializable.sol

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
pragma solidity 0.6.12;
2+
3+
/**
4+
* @title Initializable
5+
*
6+
* @dev Helper contract to support initializer functions. To use it, replace
7+
* the constructor with a function that has the `initializer` modifier.
8+
* WARNING: Unlike constructors, initializer functions must be manually
9+
* invoked. This applies both to deploying an Initializable contract, as well
10+
* as extending an Initializable contract via inheritance.
11+
* WARNING: When used with inheritance, manual care must be taken to not invoke
12+
* a parent initializer twice, or ensure that all initializers are idempotent,
13+
* because this is not dealt with automatically as with constructors.
14+
*/
15+
contract Initializable {
16+
/**
17+
* @dev Indicates that the contract has been initialized.
18+
*/
19+
bool private initialized;
20+
21+
/**
22+
* @dev Indicates that the contract is in the process of being initialized.
23+
*/
24+
bool private initializing;
25+
26+
/**
27+
* @dev Modifier to use in the initializer function of a contract.
28+
*/
29+
modifier initializer() {
30+
require(
31+
initializing || isConstructor() || !initialized,
32+
"Contract instance has already been initialized"
33+
);
34+
35+
bool wasInitializing = initializing;
36+
initializing = true;
37+
initialized = true;
38+
39+
_;
40+
41+
initializing = wasInitializing;
42+
}
43+
44+
/// @dev Returns true if and only if the function is running in the constructor
45+
function isConstructor() private view returns (bool) {
46+
// extcodesize checks the size of the code stored in an address, and
47+
// address returns the current address. Since the code is still not
48+
// deployed when running a constructor, any checks on its code size will
49+
// yield zero, making it an effective way to detect if a contract is
50+
// under construction or not.
51+
52+
// MINOR CHANGE HERE:
53+
54+
// previous code
55+
// uint256 cs;
56+
// assembly { cs := extcodesize(address) }
57+
// return cs == 0;
58+
59+
// current code
60+
address _self = address(this);
61+
uint256 cs;
62+
assembly {
63+
cs := extcodesize(_self)
64+
}
65+
return cs == 0;
66+
}
67+
68+
// Reserved storage space to allow for layout changes in the future.
69+
uint256[50] private ______gap;
70+
}

contracts/_external/Ownable.sol

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
pragma solidity 0.6.12;
2+
3+
import "./Initializable.sol";
4+
5+
/**
6+
* @title Ownable
7+
* @dev The Ownable contract has an owner address, and provides basic authorization control
8+
* functions, this simplifies the implementation of "user permissions".
9+
*/
10+
contract Ownable is Initializable {
11+
address private _owner;
12+
13+
event OwnershipRenounced(address indexed previousOwner);
14+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
15+
16+
/**
17+
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
18+
* account.
19+
*/
20+
function initialize(address sender) public virtual initializer {
21+
_owner = sender;
22+
}
23+
24+
/**
25+
* @return the address of the owner.
26+
*/
27+
function owner() public view returns (address) {
28+
return _owner;
29+
}
30+
31+
/**
32+
* @dev Throws if called by any account other than the owner.
33+
*/
34+
modifier onlyOwner() {
35+
require(isOwner());
36+
_;
37+
}
38+
39+
/**
40+
* @return true if `msg.sender` is the owner of the contract.
41+
*/
42+
function isOwner() public view returns (bool) {
43+
return msg.sender == _owner;
44+
}
45+
46+
/**
47+
* @dev Allows the current owner to relinquish control of the contract.
48+
* @notice Renouncing to ownership will leave the contract without an owner.
49+
* It will not be possible to call the functions with the `onlyOwner`
50+
* modifier anymore.
51+
*/
52+
function renounceOwnership() public onlyOwner {
53+
emit OwnershipRenounced(_owner);
54+
_owner = address(0);
55+
}
56+
57+
/**
58+
* @dev Allows the current owner to transfer control of the contract to a newOwner.
59+
* @param newOwner The address to transfer ownership to.
60+
*/
61+
function transferOwnership(address newOwner) public onlyOwner {
62+
_transferOwnership(newOwner);
63+
}
64+
65+
/**
66+
* @dev Transfers control of the contract to a newOwner.
67+
* @param newOwner The address to transfer ownership to.
68+
*/
69+
function _transferOwnership(address newOwner) internal {
70+
require(newOwner != address(0));
71+
emit OwnershipTransferred(_owner, newOwner);
72+
_owner = newOwner;
73+
}
74+
75+
uint256[50] private ______gap;
76+
}

0 commit comments

Comments
 (0)