Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving some experimental modules to stable #621

Merged
merged 16 commits into from
Apr 12, 2019

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
pragma solidity ^0.5.0;

import "./BlacklistTransferManager.sol";
import "../../ModuleFactory.sol";
import "../../../libraries/Util.sol";
import "../../UpgradableModuleFactory.sol";
import "./BlacklistTransferManagerProxy.sol";

/**
* @title Factory for deploying BlacklistManager module
* @title Factory for deploying BlacklistTransferManager module
*/
contract BlacklistTransferManagerFactory is ModuleFactory {
contract BlacklistTransferManagerFactory is UpgradableModuleFactory {

/**
* @notice Constructor
* @param _setupCost Setup cost of the module
* @param _usageCost Usage cost of the module
* @param _logicContract Contract address that contains the logic related to `description`
* @param _polymathRegistry Address of the Polymath registry
* @param _isCostInPoly true = cost in Poly, false = USD
*/
constructor(
uint256 _setupCost,
uint256 _usageCost,
address _logicContract,
address _polymathRegistry,
bool _isCostInPoly
)
public ModuleFactory(_setupCost, _usageCost, _polymathRegistry, _isCostInPoly)
public UpgradableModuleFactory("3.0.0", _setupCost, _usageCost, _logicContract, _polymathRegistry, _isCostInPoly)
{
initialVersion = "3.0.0";
name = "BlacklistTransferManager";
title = "Blacklist Transfer Manager";
description = "Automate blacklist to restrict selling";
Expand All @@ -35,12 +35,13 @@ contract BlacklistTransferManagerFactory is ModuleFactory {
compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(3), uint8(0), uint8(0));
}

/**
* @notice used to launch the Module with the help of factory
/**
* @notice Used to launch the Module with the help of factory
* @param _data Data used for the intialization of the module factory variables
* @return address Contract address of the Module
*/
function deploy(bytes calldata _data) external returns(address) {
address blacklistTransferManager = address(new BlacklistTransferManager(msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken")));
address blacklistTransferManager = address(new BlacklistTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract));
_initializeModule(blacklistTransferManager, _data);
return blacklistTransferManager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.5.0;

import "../../../proxy/OwnedUpgradeabilityProxy.sol";
import "./BlacklistTransferManagerStorage.sol";
import "../../../Pausable.sol";
import "../../../storage/modules/ModuleStorage.sol";

/**
* @title CountTransferManager module Proxy
*/
contract BlacklistTransferManagerProxy is BlacklistTransferManagerStorage, ModuleStorage, Pausable, OwnedUpgradeabilityProxy {

/**
* @notice Constructor
* @param _securityToken Address of the security token
* @param _polyAddress Address of the polytoken
* @param _implementation representing the address of the new implementation to be set
*/
constructor (
string memory _version,
address _securityToken,
address _polyAddress,
address _implementation
)
public
ModuleStorage(_securityToken, _polyAddress)
{
require(
_implementation != address(0),
"Implementation address should not be 0x"
);
_upgradeTo(_version, _implementation);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pragma solidity ^0.5.0;

/**
* @title Contract used to store layout for the CountTransferManager storage
*/
contract BlacklistTransferManagerStorage {

struct BlacklistsDetails {
uint256 startTime;
uint256 endTime;
uint256 repeatPeriodTime;
}

//hold the different blacklist details corresponds to its name
mapping(bytes32 => BlacklistsDetails) public blacklists;

//hold the different name of blacklist corresponds to a investor
mapping(address => bytes32[]) investorToBlacklist;

//get list of the addresses for a particular blacklist
mapping(bytes32 => address[]) blacklistToInvestor;

//mapping use to store the indexes for different blacklist types for a investor
mapping(address => mapping(bytes32 => uint256)) investorToIndex;

//mapping use to store the indexes for different investor for a blacklist type
mapping(bytes32 => mapping(address => uint256)) blacklistToIndex;

bytes32[] allBlacklists;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.0;

import "../../../TransferManager/TransferManager.sol";
import "../../TransferManager/TransferManager.sol";
import "./LockUpTransferManagerStorage.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/math/Math.sol";
Expand Down Expand Up @@ -51,8 +51,8 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
* @param _from Address of the sender
* @param _amount The amount of tokens to transfer
*/
function executeTransfer(address _from, address _to, uint256 _amount, bytes calldata _data) external returns(Result) {
(Result success,) = verifyTransfer(_from, _to, _amount, _data);
function executeTransfer(address _from, address /*_to*/, uint256 _amount, bytes calldata /*_data*/) external returns(Result) {
(Result success,) = _verifyTransfer(_from, _amount);
return success;
}

Expand All @@ -69,6 +69,21 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
public
view
returns(Result, bytes32)
{
return _verifyTransfer(_from, _amount);
}

/** @notice Used to verify the transfer transaction and prevent locked up tokens from being transferred
* @param _from Address of the sender
* @param _amount The amount of tokens to transfer
*/
function _verifyTransfer(
address _from,
uint256 _amount
)
internal
view
returns(Result, bytes32)
{
// only attempt to verify the transfer if the token is unpaused, this isn't a mint txn, and there exists a lockup for this user
if (!paused && _from != address(0) && userToLockups[_from].length != 0) {
Expand Down Expand Up @@ -115,13 +130,13 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
* @param _lockupNames Array of names of the lockup
*/
function addNewLockUpTypeMulti(
uint256[] calldata _lockupAmounts,
uint256[] calldata _startTimes,
uint256[] calldata _lockUpPeriodsSeconds,
uint256[] calldata _releaseFrequenciesSeconds,
bytes32[] calldata _lockupNames
uint256[] memory _lockupAmounts,
uint256[] memory _startTimes,
uint256[] memory _lockUpPeriodsSeconds,
uint256[] memory _releaseFrequenciesSeconds,
bytes32[] memory _lockupNames
)
external
public
withPerm(ADMIN)
{
require(
Expand Down Expand Up @@ -158,15 +173,15 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
}

/**
* @notice Add the lockup to a user
* @param _userAddresses Address of the user
* @param _lockupNames Name of the lockup
* @notice Add lockups to users
* @param _userAddresses Array of addresses of the users
* @param _lockupNames Array of names of the lockups
*/
function addLockUpByNameMulti(
address[] calldata _userAddresses,
bytes32[] calldata _lockupNames
address[] memory _userAddresses,
bytes32[] memory _lockupNames
)
external
public
withPerm(ADMIN)
{
_checkLengthOfArray(_userAddresses.length, _lockupNames.length);
Expand Down Expand Up @@ -259,7 +274,7 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
* @notice Used to remove the multiple lockup type
* @param _lockupNames Array of the lockup names.
*/
function removeLockupTypeMulti(bytes32[] calldata _lockupNames) external withPerm(ADMIN) {
function removeLockupTypeMulti(bytes32[] memory _lockupNames) public withPerm(ADMIN) {
for (uint256 i = 0; i < _lockupNames.length; i++) {
_removeLockupType(_lockupNames[i]);
}
Expand All @@ -270,7 +285,7 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
* @param _userAddresses Array of addresses of the user whose tokens are locked up
* @param _lockupNames Array of the names of the lockup that needs to be removed.
*/
function removeLockUpFromUserMulti(address[] calldata _userAddresses, bytes32[] calldata _lockupNames) external withPerm(ADMIN) {
function removeLockUpFromUserMulti(address[] memory _userAddresses, bytes32[] memory _lockupNames) public withPerm(ADMIN) {
_checkLengthOfArray(_userAddresses.length, _lockupNames.length);
for (uint256 i = 0; i < _userAddresses.length; i++) {
_removeLockUpFromUser(_userAddresses[i], _lockupNames[i]);
Expand Down Expand Up @@ -374,7 +389,7 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
uint256[] memory releaseFrequencySeconds,
uint256[] memory unlockedAmounts
)
{
{
uint256 length = lockupArray.length;
lockupAmounts = new uint256[](length);
startTimes = new uint256[](length);
Expand Down Expand Up @@ -471,7 +486,7 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager

function _removeLockupType(bytes32 _lockupName) internal {
_validLockUpCheck(_lockupName);
require(lockupToUsers[_lockupName].length == 0);
require(lockupToUsers[_lockupName].length == 0, "Users attached to lockup");
// delete lockup type
delete(lockups[_lockupName]);
uint256 i = 0;
Expand Down Expand Up @@ -528,7 +543,8 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
_checkZeroAddress(_userAddress);
_checkValidName(_lockupName);
require(
userToLockups[_userAddress][userToLockupIndex[_userAddress][_lockupName]] == _lockupName
userToLockups[_userAddress][userToLockupIndex[_userAddress][_lockupName]] == _lockupName,
"User not in lockup"
);

// delete the user from the lockup type
Expand Down Expand Up @@ -583,7 +599,12 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager
{
_checkZeroAddress(_userAddress);
_checkValidStartTime(lockups[_lockupName].startTime);

if(userToLockups[_userAddress].length > 0) {
require(
userToLockups[_userAddress][userToLockupIndex[_userAddress][_lockupName]] != _lockupName,
"User already in lockup"
);
}
userToLockupIndex[_userAddress][_lockupName] = userToLockups[_userAddress].length;
lockupToUserIndex[_lockupName][_userAddress] = lockupToUsers[_lockupName].length;
userToLockups[_userAddress].push(_lockupName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.5.0;

import "./LockUpTransferManagerProxy.sol";
import "../../../UpgradableModuleFactory.sol";
import "../../UpgradableModuleFactory.sol";
import "./LockUpTransferManager.sol";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity ^0.5.0;

import "./LockUpTransferManagerStorage.sol";
import "../../../../proxy/OwnedUpgradeabilityProxy.sol";
import "../../../../Pausable.sol";
import "../../../../storage/modules/ModuleStorage.sol";
import "../../../proxy/OwnedUpgradeabilityProxy.sol";
import "../../../Pausable.sol";
import "../../../storage/modules/ModuleStorage.sol";

/**
* @title CountTransferManager module Proxy
Expand Down
14 changes: 7 additions & 7 deletions contracts/modules/TransferManager/VRTM/VolumeRestrictionTM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, TransferManager {
isGlobal
);
}
return success;
return success;
}

/**
Expand All @@ -139,15 +139,15 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, TransferManager {
address /*_to*/ ,
uint256 _amount,
bytes memory /*_data*/
)
)
public
view
returns (Result, bytes32)
{

(Result success,,,,,,) = _verifyTransfer(_from, _amount);
if (success == Result.INVALID)
return (success, bytes32(uint256(address(this)) << 96));
return (success, bytes32(uint256(address(this)) << 96));
return (Result.NA, bytes32(0));
}

Expand All @@ -160,11 +160,11 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, TransferManager {
function _verifyTransfer(
address _from,
uint256 _amount
)
)
internal
view
returns (Result, uint256, uint256, uint256, uint256, uint256, bool)
{
{
// If `_from` is present in the exemptionList or it is `0x0` address then it will not follow the vol restriction
if (!paused && _from != address(0) && exemptions.exemptIndex[_from] == 0) {
// Checking the individual restriction if the `_from` comes in the individual category
Expand Down Expand Up @@ -1141,7 +1141,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, TransferManager {
*/
function getTokensByPartition(address /*_owner*/, bytes32 /*_partition*/) external view returns(uint256){
return 0;
}
}

/**
* @notice Returns the permissions flag that are associated with Percentage transfer Manager
Expand Down
Loading