Skip to content

Commit

Permalink
Solidity 0.5.0 (#478)
Browse files Browse the repository at this point in the history
* Added truffle next

* Added refactor plugin

* Capped STO refactor

* constant to view

* Updated refactor

* added storage location to return params

* pm fixes

* Oraclize fixes

* Custom datatype fixes

* Updated refactor

* PM fixes

* Updated Oraclize

* wip

* It's compiling!

* Updated CI config

* Updated CI config

* Updated circleCI config

* Updated circleCI

* Updated CircleCI config

* Payable address changes

* reduced contract size for test

* Updated truffle

* Deployment fixed

* merge refactor

* Revert oraclize changes

* WIP

* Migrations refactoring complete

* Prettier

* refactor js

* wip

* Create insctance fixed

* Create instance changes

* await at

* log watch refactor

* Getsig fixed

* cappedsto init fn fixed

* Block number and timestamp fixed

* Await at

* toWei to BN

* Time travel fixed

* Time travel changed

* wip

* Minor fixes

* WIP

* bug fix

* WIP

* capped stro tests fixed

* Investor details fixed

* ST instance name fixed

* Checkpoint tests fixed

* CTM tests fixed

* empty bytes to 0x0

* wip

* toNumber to toString

* Whitelist changes

* ERC20 tests fixed

* WIP

* Ether dividend tests fixed

* Added fixed address

* Permissions to hex

* GPM tests fixed

* gtm tests fixed

* Coverage fixed

* updated oz

* Updated circleCI docker image

* updated coverage script

* Updated circleci config

* Updated travis script

* Updated ci scripts

* Issuance tests fixed

* MATM tests fixed

* Module registry tests fixed

* percentage tm tests fixed

* Presale tests fixed

* STR tests fixed

* ST tests fixed

* fixed z_general_permission_manager_fuzzer.js

* fixed y_scheduled_checkpoints.js

* fixed v_tracked_redemptions.js

* fixed u_module_registry_proxy.js

* fixed t_security_token_registry_proxy.js

* Updated usd tiered sto tests

* fixed r_concurrent_STO.js

* simulation WIP

* USDTSTO sim fixed

* minor cleanup

* added tolerance

* Tolerance fixed

* update version to 0.5.0

* fixed compilation errors

* Coverage script fixed

* Tests updated

* fixed 2_deploy_contracts.js

* Tests fixed

* time travel updated

* STR test fixed

* suggested changes

* Merge compilation fix

* test fixed

* STR proxy tests fixed

* reformatting

* fixed typo

* non payable owner

* triggering travis

* ST optimization

* uncommented tests
  • Loading branch information
maxsam4 authored and adamdossa committed Jan 9, 2019
1 parent ef2e32f commit cd4a7f9
Show file tree
Hide file tree
Showing 166 changed files with 9,308 additions and 7,796 deletions.
12 changes: 4 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:8
- image: maxsam4/solidity-kit
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run: yarn install
- run: sudo npm i truffle -g
- run: node --version
- run: truffle version
- run: truffle compile
Expand All @@ -18,14 +17,13 @@ jobs:
- node_modules
test:
docker:
- image: circleci/node:8
- image: maxsam4/solidity-kit
parallelism: 2
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run: yarn install
- run: sudo npm i truffle -g
- run: node --version
- run: truffle version
- run: npm run test
Expand All @@ -39,13 +37,12 @@ jobs:
path: ./test-results/mocha/results.xml
coverage:
docker:
- image: circleci/node:8
- image: maxsam4/solidity-kit
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run: yarn install
- run: sudo npm i truffle -g
- run: node --version
- run: truffle version
- run:
Expand All @@ -59,13 +56,12 @@ jobs:
path: ./coverage/lcov.info
docs:
docker:
- image: circleci/node:8
- image: maxsam4/solidity-kit
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run: yarn install
- run: sudo npm i truffle -g
- run: node --version
- run: truffle version
- run: npm run docs
Expand Down
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ module.exports = {
testCommand: 'node ../node_modules/.bin/truffle test `find test/*.js ! -name a_poly_oracle.js -and ! -name s_v130_to_v140_upgrade.js -and ! -name q_usd_tiered_sto_sim.js -and ! -name z_general_permission_manager_fuzzer.js` --network coverage',
deepSkip: true,
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles', 'libraries/KindMath.sol', 'libraries/BokkyPooBahsDateTimeLibrary.sol', 'storage', 'modules/Experimental'],
forceParse: ['mocks', 'oracles', 'modules/Experimental']
forceParse: ['mocks', 'oracles', 'helpers', 'modules/Experimental']
};
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ cache:
- node_modules
jobs:
include:
- stage: test
- stage: Test
install:
- echo -ne '\n' | sudo add-apt-repository ppa:ethereum/ethereum
- sudo apt-get update
- sudo apt-get install -y dpkg
- sudo apt-get install -y solc
- yarn install
before_script: truffle version
script: npm run test
notifications:
Expand Down
9 changes: 4 additions & 5 deletions contracts/FeatureRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "./ReclaimTokens.sol";
import "./interfaces/IFeatureRegistry.sol";
Expand All @@ -7,8 +7,7 @@ import "./interfaces/IFeatureRegistry.sol";
* @title Registry for managing polymath feature switches
*/
contract FeatureRegistry is IFeatureRegistry, ReclaimTokens {

mapping (bytes32 => bool) public featureStatus;
mapping(bytes32 => bool) public featureStatus;

event ChangeFeatureStatus(string _nameKey, bool _newStatus);

Expand All @@ -17,7 +16,7 @@ contract FeatureRegistry is IFeatureRegistry, ReclaimTokens {
* @param _nameKey is the key for the feature status mapping
* @return bool
*/
function getFeatureStatus(string _nameKey) external view returns(bool) {
function getFeatureStatus(string calldata _nameKey) external view returns(bool) {
bytes32 key = keccak256(bytes(_nameKey));
return featureStatus[key];
}
Expand All @@ -28,7 +27,7 @@ contract FeatureRegistry is IFeatureRegistry, ReclaimTokens {
* @param _nameKey is the key for the feature status mapping
* @param _newStatus is the new feature status
*/
function setFeatureStatus(string _nameKey, bool _newStatus) public onlyOwner {
function setFeatureStatus(string calldata _nameKey, bool _newStatus) external onlyOwner {
bytes32 key = keccak256(bytes(_nameKey));
require(featureStatus[key] != _newStatus, "Status unchanged");
emit ChangeFeatureStatus(_nameKey, _newStatus);
Expand Down
8 changes: 3 additions & 5 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pragma solidity ^0.4.24;

pragma solidity ^0.5.0;

contract Migrations {

address public owner;

uint public lastCompletedMigration;
Expand All @@ -16,11 +14,11 @@ contract Migrations {
owner = msg.sender;
}

function setCompleted(uint _completed)public restricted {
function setCompleted(uint _completed) public restricted {
lastCompletedMigration = _completed;
}

function upgrade(address _newAddress)public restricted {
function upgrade(address _newAddress) public restricted {
Migrations upgraded = Migrations(_newAddress);
upgraded.setCompleted(lastCompletedMigration);
}
Expand Down
71 changes: 38 additions & 33 deletions contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "./interfaces/IModuleRegistry.sol";
Expand Down Expand Up @@ -41,7 +41,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {

// Emit when network becomes paused
event Pause(uint256 _timestammp);
// Emit when network becomes unpaused
// Emit when network becomes unpaused
event Unpause(uint256 _timestamp);
// Emit when Module is used by the SecurityToken
event ModuleUsed(address indexed _moduleFactory, address indexed _securityToken);
Expand All @@ -62,16 +62,15 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner(),"sender must be owner");
require(msg.sender == owner(), "sender must be owner");
_;
}

/**
* @notice Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPausedOrOwner() {
if (msg.sender == owner())
_;
if (msg.sender == owner()) _;
else {
require(!isPaused(), "Already paused");
_;
Expand Down Expand Up @@ -99,13 +98,12 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
/////////////////////////////

// Constructor
constructor () public
{
constructor() public {

}

function initialize(address _polymathRegistry, address _owner) external payable {
require(!getBool(Encoder.getKey("initialised")),"already initialized");
require(!getBool(Encoder.getKey("initialised")), "already initialized");
require(_owner != address(0) && _polymathRegistry != address(0), "0x address is invalid");
set(Encoder.getKey("polymathRegistry"), _polymathRegistry);
set(Encoder.getKey("owner"), _owner);
Expand All @@ -124,7 +122,10 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
// This if statement is required to be able to add modules from the token proxy contract during deployment
if (ISecurityTokenRegistry(getAddress(Encoder.getKey("securityTokenRegistry"))).isSecurityToken(msg.sender)) {
if (IFeatureRegistry(getAddress(Encoder.getKey("featureRegistry"))).getFeatureStatus("customModulesAllowed")) {
require(getBool(Encoder.getKey("verified", _moduleFactory)) || IOwnable(_moduleFactory).owner() == IOwnable(msg.sender).owner(),"ModuleFactory must be verified or SecurityToken owner must be ModuleFactory owner");
require(
getBool(Encoder.getKey("verified", _moduleFactory)) || IOwnable(_moduleFactory).owner() == IOwnable(msg.sender).owner(),
"ModuleFactory must be verified or SecurityToken owner must be ModuleFactory owner"
);
} else {
require(getBool(Encoder.getKey("verified", _moduleFactory)), "ModuleFactory must be verified");
}
Expand All @@ -149,7 +150,10 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
*/
function registerModule(address _moduleFactory) external whenNotPausedOrOwner {
if (IFeatureRegistry(getAddress(Encoder.getKey("featureRegistry"))).getFeatureStatus("customModulesAllowed")) {
require(msg.sender == IOwnable(_moduleFactory).owner() || msg.sender == owner(),"msg.sender must be the Module Factory owner or registry curator");
require(
msg.sender == IOwnable(_moduleFactory).owner() || msg.sender == owner(),
"msg.sender must be the Module Factory owner or registry curator"
);
} else {
require(msg.sender == owner(), "Only owner allowed to register modules");
}
Expand All @@ -173,7 +177,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
uint256(getArrayAddress(Encoder.getKey("moduleList", uint256(moduleType))).length)
);
pushArray(Encoder.getKey("moduleList", uint256(moduleType)), _moduleFactory);
emit ModuleRegistered (_moduleFactory, IOwnable(_moduleFactory).owner());
emit ModuleRegistered(_moduleFactory, IOwnable(_moduleFactory).owner());
}

/**
Expand Down Expand Up @@ -232,7 +236,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @return list of tags
* @return corresponding list of module factories
*/
function getTagsByTypeAndToken(uint8 _moduleType, address _securityToken) external view returns(bytes32[], address[]) {
function getTagsByTypeAndToken(uint8 _moduleType, address _securityToken) external view returns(bytes32[] memory, address[] memory) {
address[] memory modules = getModulesByTypeAndToken(_moduleType, _securityToken);
return _tagsByModules(modules);
}
Expand All @@ -243,7 +247,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @return list of tags
* @return corresponding list of module factories
*/
function getTagsByType(uint8 _moduleType) external view returns(bytes32[], address[]) {
function getTagsByType(uint8 _moduleType) external view returns(bytes32[] memory, address[] memory) {
address[] memory modules = getModulesByType(_moduleType);
return _tagsByModules(modules);
}
Expand All @@ -254,7 +258,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @return list of tags
* @return corresponding list of module factories
*/
function _tagsByModules(address[] _modules) internal view returns(bytes32[], address[]) {
function _tagsByModules(address[] memory _modules) internal view returns(bytes32[] memory, address[] memory) {
uint256 counter = 0;
uint256 i;
uint256 j;
Expand All @@ -281,7 +285,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _factoryAddress is the address of the module factory
* @return address array which contains the list of securityTokens that use that module factory
*/
function getReputationByFactory(address _factoryAddress) external view returns(address[]) {
function getReputationByFactory(address _factoryAddress) external view returns(address[] memory) {
return getArrayAddress(Encoder.getKey("reputation", _factoryAddress));
}

Expand All @@ -290,7 +294,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _moduleType Type of Module
* @return address array that contains the list of addresses of module factory contracts.
*/
function getModulesByType(uint8 _moduleType) public view returns(address[]) {
function getModulesByType(uint8 _moduleType) public view returns(address[] memory) {
return getArrayAddress(Encoder.getKey("moduleList", uint256(_moduleType)));
}

Expand All @@ -300,37 +304,38 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
* @param _securityToken is the address of SecurityToken
* @return address array that contains the list of available addresses of module factory contracts.
*/
function getModulesByTypeAndToken(uint8 _moduleType, address _securityToken) public view returns (address[]) {
function getModulesByTypeAndToken(uint8 _moduleType, address _securityToken) public view returns(address[] memory) {
uint256 _len = getArrayAddress(Encoder.getKey("moduleList", uint256(_moduleType))).length;
address[] memory _addressList = getArrayAddress(Encoder.getKey("moduleList", uint256(_moduleType)));
bool _isCustomModuleAllowed = IFeatureRegistry(getAddress(Encoder.getKey("featureRegistry"))).getFeatureStatus("customModulesAllowed");
bool _isCustomModuleAllowed = IFeatureRegistry(getAddress(Encoder.getKey("featureRegistry"))).getFeatureStatus(
"customModulesAllowed"
);
uint256 counter = 0;
for (uint256 i = 0; i < _len; i++) {
if (_isCustomModuleAllowed) {
if (IOwnable(_addressList[i]).owner() == IOwnable(_securityToken).owner() || getBool(Encoder.getKey("verified", _addressList[i])))
if(_isCompatibleModule(_addressList[i], _securityToken))
counter++;
}
else if (getBool(Encoder.getKey("verified", _addressList[i]))) {
if(_isCompatibleModule(_addressList[i], _securityToken))
counter++;
if (IOwnable(_addressList[i]).owner() == IOwnable(_securityToken).owner() || getBool(
Encoder.getKey("verified", _addressList[i])
)) if (_isCompatibleModule(_addressList[i], _securityToken)) counter++;
} else if (getBool(Encoder.getKey("verified", _addressList[i]))) {
if (_isCompatibleModule(_addressList[i], _securityToken)) counter++;
}
}
address[] memory _tempArray = new address[](counter);
counter = 0;
for (uint256 j = 0; j < _len; j++) {
if (_isCustomModuleAllowed) {
if (IOwnable(_addressList[j]).owner() == IOwnable(_securityToken).owner() || getBool(Encoder.getKey("verified", _addressList[j]))) {
if(_isCompatibleModule(_addressList[j], _securityToken)) {
if (IOwnable(_addressList[j]).owner() == IOwnable(_securityToken).owner() || getBool(
Encoder.getKey("verified", _addressList[j])
)) {
if (_isCompatibleModule(_addressList[j], _securityToken)) {
_tempArray[counter] = _addressList[j];
counter ++;
counter++;
}
}
}
else if (getBool(Encoder.getKey("verified", _addressList[j]))) {
if(_isCompatibleModule(_addressList[j], _securityToken)) {
} else if (getBool(Encoder.getKey("verified", _addressList[j]))) {
if (_isCompatibleModule(_addressList[j], _securityToken)) {
_tempArray[counter] = _addressList[j];
counter ++;
counter++;
}
}
}
Expand All @@ -345,7 +350,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
require(_tokenContract != address(0), "0x address is invalid");
IERC20 token = IERC20(_tokenContract);
uint256 balance = token.balanceOf(address(this));
require(token.transfer(owner(), balance),"token transfer failed");
require(token.transfer(owner(), balance), "token transfer failed");
}

/**
Expand Down
5 changes: 2 additions & 3 deletions contracts/Pausable.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

/**
* @title Utility contract to allow pausing and unpausing of certain functions
*/
contract Pausable {

event Pause(uint256 _timestammp);
event Unpause(uint256 _timestamp);

Expand All @@ -26,7 +25,7 @@ contract Pausable {
_;
}

/**
/**
* @notice Called by the owner to pause, triggers stopped state
*/
function _pause() internal whenNotPaused {
Expand Down
10 changes: 4 additions & 6 deletions contracts/PolymathRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pragma solidity ^0.4.24;
pragma solidity ^0.5.0;

import "./ReclaimTokens.sol";

/**
* @title Core functionality for registry upgradability
*/
contract PolymathRegistry is ReclaimTokens {

mapping (bytes32 => address) public storedAddresses;
mapping(bytes32 => address) public storedAddresses;

event ChangeAddress(string _nameKey, address indexed _oldAddress, address indexed _newAddress);

Expand All @@ -16,7 +15,7 @@ contract PolymathRegistry is ReclaimTokens {
* @param _nameKey is the key for the contract address mapping
* @return address
*/
function getAddress(string _nameKey) external view returns(address) {
function getAddress(string calldata _nameKey) external view returns(address) {
bytes32 key = keccak256(bytes(_nameKey));
require(storedAddresses[key] != address(0), "Invalid address key");
return storedAddresses[key];
Expand All @@ -27,11 +26,10 @@ contract PolymathRegistry is ReclaimTokens {
* @param _nameKey is the key for the contract address mapping
* @param _newAddress is the new contract address
*/
function changeAddress(string _nameKey, address _newAddress) external onlyOwner {
function changeAddress(string calldata _nameKey, address _newAddress) external onlyOwner {
bytes32 key = keccak256(bytes(_nameKey));
emit ChangeAddress(_nameKey, storedAddresses[key], _newAddress);
storedAddresses[key] = _newAddress;
}


}
Loading

0 comments on commit cd4a7f9

Please sign in to comment.