diff --git a/contracts/libraries/VolumeRestrictionLib.sol b/contracts/libraries/VolumeRestrictionLib.sol index e1e94a50b..9f71d3fed 100644 --- a/contracts/libraries/VolumeRestrictionLib.sol +++ b/contracts/libraries/VolumeRestrictionLib.sol @@ -3,27 +3,12 @@ pragma solidity ^0.4.24; import "./BokkyPooBahsDateTimeLibrary.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../interfaces/ISecurityToken.sol"; +import "../storage/VolumeRestrictionTMStorage.sol"; library VolumeRestrictionLib { using SafeMath for uint256; - enum TypeOfPeriod { MultipleDays, OneDay, Both } - - struct RestrictedHolder { - // 1 represent true & 0 for false - uint8 seen; - // Type of period will be enum index of TypeOfPeriod enum - uint8 typeOfPeriod; - // Index of the array where the holder address lives - uint128 index; - } - - struct RestrictedData { - mapping(address => RestrictedHolder) restrictedHolders; - address[] restrictedAddresses; - } - function _checkLengthOfArray( address[] _holders, uint256[] _allowedTokens, @@ -45,14 +30,14 @@ library VolumeRestrictionLib { ); } - function _deleteHolderFromList(RestrictedData storage data, address _holder, uint8 _typeOfPeriod) public { + function deleteHolderFromList(VolumeRestrictionTMStorage.RestrictedData storage data, address _holder, uint8 _typeOfPeriod) public { // Deleting the holder if holder's type of Period is `Both` type otherwise // it will assign the given type `_typeOfPeriod` to the _holder typeOfPeriod // `_typeOfPeriod` it always be contrary to the removing restriction // if removing restriction is individual then typeOfPeriod is TypeOfPeriod.OneDay // in uint8 its value is 1. if removing restriction is daily individual then typeOfPeriod // is TypeOfPeriod.MultipleDays in uint8 its value is 0. - if (data.restrictedHolders[_holder].typeOfPeriod != uint8(TypeOfPeriod.Both)) { + if (data.restrictedHolders[_holder].typeOfPeriod != uint8(VolumeRestrictionTMStorage.TypeOfPeriod.Both)) { uint128 index = data.restrictedHolders[_holder].index; uint256 _len = data.restrictedAddresses.length; if (index != _len) { @@ -66,22 +51,22 @@ library VolumeRestrictionLib { } } - function _addRestrictionData(RestrictedData storage data, address _holder, uint8 _callFrom, uint256 _endTime) public { + function addRestrictionData(VolumeRestrictionTMStorage.RestrictedData storage data, address _holder, uint8 _callFrom, uint256 _endTime) public { uint128 index = data.restrictedHolders[_holder].index; if (data.restrictedHolders[_holder].seen == 0) { data.restrictedAddresses.push(_holder); index = uint128(data.restrictedAddresses.length); } uint8 _type = _getTypeOfPeriod(data.restrictedHolders[_holder].typeOfPeriod, _callFrom, _endTime); - data.restrictedHolders[_holder] = RestrictedHolder(uint8(1), _type, index); + data.restrictedHolders[_holder] = VolumeRestrictionTMStorage.RestrictedHolder(uint8(1), _type, index); } function _getTypeOfPeriod(uint8 _currentTypeOfPeriod, uint8 _callFrom, uint256 _endTime) internal pure returns(uint8) { if (_currentTypeOfPeriod != _callFrom && _endTime != uint256(0)) - return uint8(TypeOfPeriod.Both); + return uint8(VolumeRestrictionTMStorage.TypeOfPeriod.Both); else return _callFrom; } - -} \ No newline at end of file + +} diff --git a/contracts/modules/TransferManager/BlacklistTransferManager.sol b/contracts/modules/Experimental/TransferManager/BlacklistTransferManager.sol similarity index 99% rename from contracts/modules/TransferManager/BlacklistTransferManager.sol rename to contracts/modules/Experimental/TransferManager/BlacklistTransferManager.sol index d88fea770..d1e653803 100644 --- a/contracts/modules/TransferManager/BlacklistTransferManager.sol +++ b/contracts/modules/Experimental/TransferManager/BlacklistTransferManager.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "./ITransferManager.sol"; +import "../../TransferManager/ITransferManager.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; /** diff --git a/contracts/modules/TransferManager/BlacklistTransferManagerFactory.sol b/contracts/modules/Experimental/TransferManager/BlacklistTransferManagerFactory.sol similarity index 97% rename from contracts/modules/TransferManager/BlacklistTransferManagerFactory.sol rename to contracts/modules/Experimental/TransferManager/BlacklistTransferManagerFactory.sol index cdb7c90eb..36dd4304f 100644 --- a/contracts/modules/TransferManager/BlacklistTransferManagerFactory.sol +++ b/contracts/modules/Experimental/TransferManager/BlacklistTransferManagerFactory.sol @@ -1,8 +1,8 @@ pragma solidity ^0.4.24; import "./BlacklistTransferManager.sol"; -import "../ModuleFactory.sol"; -import "../../libraries/Util.sol"; +import "../../ModuleFactory.sol"; +import "../../../libraries/Util.sol"; /** * @title Factory for deploying BlacklistManager module diff --git a/contracts/modules/TransferManager/LockUpTransferManager.sol b/contracts/modules/Experimental/TransferManager/LockUpTransferManager.sol similarity index 99% rename from contracts/modules/TransferManager/LockUpTransferManager.sol rename to contracts/modules/Experimental/TransferManager/LockUpTransferManager.sol index 993bbd5bb..85ae126fa 100644 --- a/contracts/modules/TransferManager/LockUpTransferManager.sol +++ b/contracts/modules/Experimental/TransferManager/LockUpTransferManager.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "./ITransferManager.sol"; +import "../../TransferManager/ITransferManager.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; contract LockUpTransferManager is ITransferManager { diff --git a/contracts/modules/TransferManager/LockUpTransferManagerFactory.sol b/contracts/modules/Experimental/TransferManager/LockUpTransferManagerFactory.sol similarity index 98% rename from contracts/modules/TransferManager/LockUpTransferManagerFactory.sol rename to contracts/modules/Experimental/TransferManager/LockUpTransferManagerFactory.sol index 3f5e7b31a..22581eba4 100644 --- a/contracts/modules/TransferManager/LockUpTransferManagerFactory.sol +++ b/contracts/modules/Experimental/TransferManager/LockUpTransferManagerFactory.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "../ModuleFactory.sol"; +import "../../ModuleFactory.sol"; import "./LockUpTransferManager.sol"; /** diff --git a/contracts/modules/Wallet/IWallet.sol b/contracts/modules/Experimental/Wallet/IWallet.sol similarity index 83% rename from contracts/modules/Wallet/IWallet.sol rename to contracts/modules/Experimental/Wallet/IWallet.sol index ea5c918d8..96affd472 100644 --- a/contracts/modules/Wallet/IWallet.sol +++ b/contracts/modules/Experimental/Wallet/IWallet.sol @@ -1,7 +1,7 @@ pragma solidity ^0.4.24; -import "../../Pausable.sol"; -import "../Module.sol"; +import "../../../Pausable.sol"; +import "../../Module.sol"; /** * @title Interface to be implemented by all Wallet modules diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Experimental/Wallet/VestingEscrowWallet.sol similarity index 99% rename from contracts/modules/Wallet/VestingEscrowWallet.sol rename to contracts/modules/Experimental/Wallet/VestingEscrowWallet.sol index 17f6dbb08..c53e1143f 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Experimental/Wallet/VestingEscrowWallet.sol @@ -1,7 +1,7 @@ pragma solidity ^0.4.24; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -import "./VestingEscrowWalletStorage.sol"; +import "../../../storage/VestingEscrowWalletStorage.sol"; import "./IWallet.sol"; /** diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Experimental/Wallet/VestingEscrowWalletFactory.sol similarity index 94% rename from contracts/modules/Wallet/VestingEscrowWalletFactory.sol rename to contracts/modules/Experimental/Wallet/VestingEscrowWalletFactory.sol index 238d571ea..2e35453f0 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Experimental/Wallet/VestingEscrowWalletFactory.sol @@ -1,9 +1,9 @@ pragma solidity ^0.4.24; -import "../../proxy/VestingEscrowWalletProxy.sol"; -import "../../interfaces/IBoot.sol"; -import "../ModuleFactory.sol"; -import "../../libraries/Util.sol"; +import "../../../proxy/VestingEscrowWalletProxy.sol"; +import "../../../interfaces/IBoot.sol"; +import "../../ModuleFactory.sol"; +import "../../../libraries/Util.sol"; /** * @title Factory for deploying VestingEscrowWallet module diff --git a/contracts/modules/STO/USDTieredSTO.sol b/contracts/modules/STO/USDTieredSTO.sol index b3a248da5..97345ad51 100644 --- a/contracts/modules/STO/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTieredSTO.sol @@ -7,7 +7,7 @@ import "../../RegistryUpdater.sol"; import "../../libraries/DecimalMath.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "openzeppelin-solidity/contracts/ReentrancyGuard.sol"; -import "./USDTieredSTOStorage.sol"; +import "../../storage/USDTieredSTOStorage.sol"; /** * @title STO module for standard capped crowdsale diff --git a/contracts/modules/TransferManager/GeneralTransferManager.sol b/contracts/modules/TransferManager/GeneralTransferManager.sol index ef7d15e98..dc7eabd4b 100644 --- a/contracts/modules/TransferManager/GeneralTransferManager.sol +++ b/contracts/modules/TransferManager/GeneralTransferManager.sol @@ -1,7 +1,7 @@ pragma solidity ^0.4.24; import "./ITransferManager.sol"; -import "./GeneralTransferManagerStorage.sol"; +import "../../storage/GeneralTransferManagerStorage.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; /** diff --git a/contracts/modules/TransferManager/VolumeRestrictionTM.sol b/contracts/modules/TransferManager/VolumeRestrictionTM.sol index 5cf1e4ac6..69b036aa4 100644 --- a/contracts/modules/TransferManager/VolumeRestrictionTM.sol +++ b/contracts/modules/TransferManager/VolumeRestrictionTM.sol @@ -1,9 +1,9 @@ pragma solidity ^0.4.24; import "./ITransferManager.sol"; -import "./VolumeRestrictionTMStorage.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../../libraries/BokkyPooBahsDateTimeLibrary.sol"; +import "../../libraries/VolumeRestrictionLib.sol"; contract VolumeRestrictionTM is VolumeRestrictionTMStorage, ITransferManager { @@ -212,7 +212,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, ITransferManager { _endTime, RestrictionType(_restrictionType) ); - VolumeRestrictionLib._addRestrictionData(holderData, _holder, uint8(TypeOfPeriod.MultipleDays), individualRestriction[_holder].endTime); + VolumeRestrictionLib.addRestrictionData(holderData, _holder, uint8(TypeOfPeriod.MultipleDays), individualRestriction[_holder].endTime); emit AddIndividualRestriction( _holder, _allowedTokens, @@ -275,7 +275,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, ITransferManager { _endTime, RestrictionType(_restrictionType) ); - VolumeRestrictionLib._addRestrictionData(holderData, _holder, uint8(TypeOfPeriod.OneDay), individualRestriction[_holder].endTime); + VolumeRestrictionLib.addRestrictionData(holderData, _holder, uint8(TypeOfPeriod.OneDay), individualRestriction[_holder].endTime); emit AddIndividualDailyRestriction( _holder, _allowedTokens, @@ -447,7 +447,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, ITransferManager { require(_holder != address(0)); require(individualRestriction[_holder].endTime != 0); individualRestriction[_holder] = VolumeRestriction(0, 0, 0, 0, RestrictionType(0)); - VolumeRestrictionLib._deleteHolderFromList(holderData, _holder, uint8(TypeOfPeriod.OneDay)); + VolumeRestrictionLib.deleteHolderFromList(holderData, _holder, uint8(TypeOfPeriod.OneDay)); userToBucket[_holder].lastTradedDayTime = 0; userToBucket[_holder].sumOfLastPeriod = 0; userToBucket[_holder].daysCovered = 0; @@ -477,7 +477,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, ITransferManager { require(_holder != address(0)); require(individualDailyRestriction[_holder].endTime != 0); individualDailyRestriction[_holder] = VolumeRestriction(0, 0, 0, 0, RestrictionType(0)); - VolumeRestrictionLib._deleteHolderFromList(holderData, _holder, uint8(TypeOfPeriod.MultipleDays)); + VolumeRestrictionLib.deleteHolderFromList(holderData, _holder, uint8(TypeOfPeriod.MultipleDays)); userToBucket[_holder].dailyLastTradedDayTime = 0; emit IndividualDailyRestrictionRemoved(_holder); } diff --git a/contracts/proxy/GeneralTransferManagerProxy.sol b/contracts/proxy/GeneralTransferManagerProxy.sol index cb9b69070..0fbaa7880 100644 --- a/contracts/proxy/GeneralTransferManagerProxy.sol +++ b/contracts/proxy/GeneralTransferManagerProxy.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "../modules/TransferManager/GeneralTransferManagerStorage.sol"; +import "../storage/GeneralTransferManagerStorage.sol"; import "./OwnedProxy.sol"; import "../Pausable.sol"; import "../modules/ModuleStorage.sol"; diff --git a/contracts/proxy/USDTieredSTOProxy.sol b/contracts/proxy/USDTieredSTOProxy.sol index 12cf8fdb1..a412a8278 100644 --- a/contracts/proxy/USDTieredSTOProxy.sol +++ b/contracts/proxy/USDTieredSTOProxy.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "../modules/STO/USDTieredSTOStorage.sol"; +import "../storage/USDTieredSTOStorage.sol"; import "./OwnedProxy.sol"; import "../Pausable.sol"; import "openzeppelin-solidity/contracts/ReentrancyGuard.sol"; diff --git a/contracts/proxy/VestingEscrowWalletProxy.sol b/contracts/proxy/VestingEscrowWalletProxy.sol index 0138e0402..8f7be97ce 100644 --- a/contracts/proxy/VestingEscrowWalletProxy.sol +++ b/contracts/proxy/VestingEscrowWalletProxy.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "../modules/Wallet/VestingEscrowWalletStorage.sol"; +import "../storage/VestingEscrowWalletStorage.sol"; import "./OwnedProxy.sol"; import "../Pausable.sol"; import "../modules/ModuleStorage.sol"; diff --git a/contracts/proxy/VolumeRestrictionTMProxy.sol b/contracts/proxy/VolumeRestrictionTMProxy.sol index e8c24e6be..0f5cc7f5a 100644 --- a/contracts/proxy/VolumeRestrictionTMProxy.sol +++ b/contracts/proxy/VolumeRestrictionTMProxy.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "../modules/TransferManager/VolumeRestrictionTMStorage.sol"; +import "../storage/VolumeRestrictionTMStorage.sol"; import "./OwnedProxy.sol"; import "../Pausable.sol"; import "../modules/ModuleStorage.sol"; diff --git a/contracts/modules/TransferManager/GeneralTransferManagerStorage.sol b/contracts/storage/GeneralTransferManagerStorage.sol similarity index 100% rename from contracts/modules/TransferManager/GeneralTransferManagerStorage.sol rename to contracts/storage/GeneralTransferManagerStorage.sol diff --git a/contracts/modules/STO/USDTieredSTOStorage.sol b/contracts/storage/USDTieredSTOStorage.sol similarity index 98% rename from contracts/modules/STO/USDTieredSTOStorage.sol rename to contracts/storage/USDTieredSTOStorage.sol index c9df0f24c..f801000e0 100644 --- a/contracts/modules/STO/USDTieredSTOStorage.sol +++ b/contracts/storage/USDTieredSTOStorage.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "../../interfaces/IERC20.sol"; +import "../interfaces/IERC20.sol"; /** * @title Contract used to store layout for the USDTieredSTO storage diff --git a/contracts/modules/Wallet/VestingEscrowWalletStorage.sol b/contracts/storage/VestingEscrowWalletStorage.sol similarity index 100% rename from contracts/modules/Wallet/VestingEscrowWalletStorage.sol rename to contracts/storage/VestingEscrowWalletStorage.sol diff --git a/contracts/modules/TransferManager/VolumeRestrictionTMStorage.sol b/contracts/storage/VolumeRestrictionTMStorage.sol similarity index 81% rename from contracts/modules/TransferManager/VolumeRestrictionTMStorage.sol rename to contracts/storage/VolumeRestrictionTMStorage.sol index 9eb776ff0..9718c2c09 100644 --- a/contracts/modules/TransferManager/VolumeRestrictionTMStorage.sol +++ b/contracts/storage/VolumeRestrictionTMStorage.sol @@ -1,7 +1,5 @@ pragma solidity ^0.4.24; -import "../../libraries/VolumeRestrictionLib.sol"; - /** * @title Storage layout for VolumeRestrictionTM */ @@ -11,6 +9,20 @@ contract VolumeRestrictionTMStorage { enum TypeOfPeriod { MultipleDays, OneDay, Both } + struct RestrictedHolder { + // 1 represent true & 0 for false + uint8 seen; + // Type of period will be enum index of TypeOfPeriod enum + uint8 typeOfPeriod; + // Index of the array where the holder address lives + uint128 index; + } + + struct RestrictedData { + mapping(address => RestrictedHolder) restrictedHolders; + address[] restrictedAddresses; + } + struct VolumeRestriction { // If typeOfRestriction is `Percentage` then allowedTokens will be in // the % (w.r.t to totalSupply) with a multiplier of 10**16 . else it @@ -43,11 +55,9 @@ contract VolumeRestrictionTMStorage { mapping(address => BucketDetails) internal userToBucket; // Storing the information related to default restriction mapping(address => BucketDetails) internal defaultUserToBucket; - // List of wallets that are exempted from all the restrictions applied by the this contract - /* mapping(address => bool) public exemptList; */ // Restricted data (refernce from the VolumeRestrictionLib library ) - VolumeRestrictionLib.RestrictedData holderData; - // Holde exempt index + RestrictedData holderData; + // Hold exempt index mapping(address => uint256) exemptIndex; address[] public exemptAddresses; diff --git a/test/y_volume_restriction_tm.js b/test/y_volume_restriction_tm.js index 335e76d1d..0a9894032 100644 --- a/test/y_volume_restriction_tm.js +++ b/test/y_volume_restriction_tm.js @@ -543,7 +543,7 @@ contract('VolumeRestrictionTransferManager', accounts => { await I_VolumeRestrictionTM.addIndividualRestrictionMulti( [account_investor2, account_delegate3, account_investor4], [web3.utils.toWei("12"), web3.utils.toWei("10"), web3.utils.toWei("15")], - [latestTime() + duration.seconds(2), latestTime() + duration.seconds(2), latestTime() + duration.seconds(2)], + [0, 0, 0], [3, 4, 5], [latestTime() + duration.days(5), latestTime() + duration.days(6), latestTime() + duration.days(7)], [0,0,0],