From 54362474c438526b7ac04185e5dd89c9b61b3c89 Mon Sep 17 00:00:00 2001 From: Satyam Agrawal Date: Thu, 13 Jun 2019 20:18:56 +0530 Subject: [PATCH] Specific contract type used (#683) * specific contract type used * add more type contract * remove the redundant KindMath * remove unnecessary casting * Merge fixes --- contracts/ModuleRegistry.sol | 2 +- contracts/interfaces/IModuleRegistry.sol | 2 +- contracts/libraries/TokenLib.sol | 27 +++++++++--------- contracts/mocks/Dummy/DummySTO.sol | 2 +- contracts/mocks/Dummy/DummySTOFactory.sol | 2 +- contracts/mocks/MockBurnFactory.sol | 2 +- contracts/mocks/MockRedemptionManager.sol | 10 +++---- .../Dividend/DividendCheckpoint.sol | 16 +++++------ .../ERC20/ERC20DividendCheckpoint.sol | 10 +++---- .../ERC20/ERC20DividendCheckpointFactory.sol | 2 +- .../Ether/EtherDividendCheckpoint.sol | 9 +++--- .../Ether/EtherDividendCheckpointFactory.sol | 2 +- .../PLCR/PLCRVotingCheckpointFactory.sol | 2 +- .../Transparent/WeightedVoteCheckpoint.sol | 10 +++---- .../WeightedVoteCheckpointFactory.sol | 2 +- .../Experimental/Burn/TrackedRedemption.sol | 2 +- .../Burn/TrackedRedemptionFactory.sol | 2 +- .../Mixed/ScheduledCheckpoint.sol | 2 +- .../Mixed/ScheduledCheckpointFactory.sol | 2 +- .../KYCTransferManagerFactory.sol | 2 +- .../SignedTransferManagerFactory.sol | 2 +- contracts/modules/Module.sol | 8 +++--- contracts/modules/ModuleFactory.sol | 8 +++--- .../GeneralPermissionManager.sol | 4 +-- .../GeneralPermissionManagerFactory.sol | 2 +- contracts/modules/STO/Capped/CappedSTO.sol | 4 +-- .../modules/STO/Capped/CappedSTOFactory.sol | 2 +- contracts/modules/STO/PreSale/PreSaleSTO.sol | 2 +- .../modules/STO/PreSale/PreSaleSTOFactory.sol | 2 +- .../modules/STO/USDTiered/USDTieredSTO.sol | 28 +++++++++---------- .../STO/USDTiered/USDTieredSTOFactory.sol | 2 +- .../STO/USDTiered/USDTieredSTOStorage.sol | 4 ++- .../BTM/BlacklistTransferManager.sol | 2 +- .../BTM/BlacklistTransferManagerFactory.sol | 2 +- .../CTM/CountTransferManager.sol | 4 +-- .../CTM/CountTransferManagerFactory.sol | 2 +- .../GTM/GeneralTransferManager.sol | 2 +- .../GTM/GeneralTransferManagerFactory.sol | 2 +- .../LTM/LockUpTransferManager.sol | 4 +-- .../LTM/LockUpTransferManagerFactory.sol | 2 +- .../ManualApprovalTransferManagerFactory.sol | 2 +- .../PTM/PercentageTransferManager.sol | 4 +-- .../PTM/PercentageTransferManagerFactory.sol | 2 +- .../TransferManager/TransferManager.sol | 2 +- .../VRTM/VolumeRestrictionTM.sol | 4 +-- .../VRTM/VolumeRestrictionTMFactory.sol | 2 +- contracts/modules/UpgradableModuleFactory.sol | 2 +- .../modules/Wallet/VestingEscrowWallet.sol | 8 +++--- .../Wallet/VestingEscrowWalletFactory.sol | 2 +- contracts/oracles/MakerDAOOracle.sol | 10 +++---- contracts/storage/modules/ModuleStorage.sol | 5 ++-- contracts/tokens/STGetter.sol | 18 ++++-------- contracts/tokens/SecurityToken.sol | 23 +++++++-------- contracts/tokens/SecurityTokenProxy.sol | 2 +- contracts/tokens/SecurityTokenStorage.sol | 16 +++++++---- 55 files changed, 151 insertions(+), 149 deletions(-) diff --git a/contracts/ModuleRegistry.sol b/contracts/ModuleRegistry.sol index b358763fc..92c27b7a3 100644 --- a/contracts/ModuleRegistry.sol +++ b/contracts/ModuleRegistry.sol @@ -325,7 +325,7 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage { * @notice Returns the verified status, and reputation of the entered Module Factory * @param _factoryAddress is the address of the module factory * @return bool indicating whether module factory is verified - * @return address of factory owner + * @return address of the factory owner * @return address array which contains the list of securityTokens that use that module factory */ function getFactoryDetails(address _factoryAddress) external view returns(bool, address, address[] memory) { diff --git a/contracts/interfaces/IModuleRegistry.sol b/contracts/interfaces/IModuleRegistry.sol index a7e6adbd0..44785c074 100644 --- a/contracts/interfaces/IModuleRegistry.sol +++ b/contracts/interfaces/IModuleRegistry.sol @@ -74,7 +74,7 @@ interface IModuleRegistry { * @notice Returns the verified status, and reputation of the entered Module Factory * @param _factoryAddress is the address of the module factory * @return bool indicating whether module factory is verified - * @return address of factory owner + * @return address of the factory owner * @return address array which contains the list of securityTokens that use that module factory */ function getFactoryDetails(address _factoryAddress) external view returns(bool isVerified, address factoryOwner, address[] memory usingTokens); diff --git a/contracts/libraries/TokenLib.sol b/contracts/libraries/TokenLib.sol index 9c892bbce..8355a3dff 100644 --- a/contracts/libraries/TokenLib.sol +++ b/contracts/libraries/TokenLib.sol @@ -6,8 +6,10 @@ import "../modules/UpgradableModuleFactory.sol"; import "../interfaces/IDataStore.sol"; import "../tokens/SecurityTokenStorage.sol"; import "../interfaces/ITransferManager.sol"; +import "../modules/UpgradableModuleFactory.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../modules/PermissionManager/IPermissionManager.sol"; +import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; library TokenLib { @@ -138,11 +140,11 @@ library TokenLib { * @notice Unarchives a module attached to the SecurityToken * @param _moduleData Storage data */ - function unarchiveModule(address _moduleRegistry, SecurityTokenStorage.ModuleData storage _moduleData) external { + function unarchiveModule(IModuleRegistry _moduleRegistry, SecurityTokenStorage.ModuleData storage _moduleData) external { require(_moduleData.isArchived, "Module unarchived"); /*solium-disable-next-line security/no-block-members*/ // Check the version is still valid - can only be false if token was upgraded between unarchive / archive - IModuleRegistry(_moduleRegistry).useModule(_moduleData.moduleFactory, true); + _moduleRegistry.useModule(_moduleData.moduleFactory, true); emit ModuleUnarchived(_moduleData.moduleTypes, _moduleData.module); _moduleData.isArchived = false; } @@ -151,10 +153,10 @@ library TokenLib { * @notice Upgrades a module attached to the SecurityToken * @param _moduleData Storage data */ - function upgradeModule(address _moduleRegistry, SecurityTokenStorage.ModuleData storage _moduleData) external { + function upgradeModule(IModuleRegistry _moduleRegistry, SecurityTokenStorage.ModuleData storage _moduleData) external { require(_moduleData.module != address(0), "Module missing"); //Check module is verified and within version bounds - IModuleRegistry(_moduleRegistry).useModule(_moduleData.moduleFactory, true); + _moduleRegistry.useModule(_moduleData.moduleFactory, true); // Will revert if module isn't upgradable UpgradableModuleFactory(_moduleData.moduleFactory).upgrade(_moduleData.module); emit ModuleUpgraded(_moduleData.moduleTypes, _moduleData.module); @@ -231,19 +233,19 @@ library TokenLib { address _module, uint256 _change, bool _increase, - address _polyToken, + IERC20 _polyToken, mapping(address => SecurityTokenStorage.ModuleData) storage _modulesToData ) external { require(_modulesToData[_module].module != address(0), "Module missing"); - uint256 currentAllowance = IPoly(_polyToken).allowance(address(this), _module); + uint256 currentAllowance = _polyToken.allowance(address(this), _module); uint256 newAllowance; if (_increase) { - require(IPoly(_polyToken).increaseApproval(_module, _change), "IncreaseApproval fail"); + require(IPoly(address(_polyToken)).increaseApproval(_module, _change), "IncreaseApproval fail"); newAllowance = currentAllowance.add(_change); } else { - require(IPoly(_polyToken).decreaseApproval(_module, _change), "Insufficient allowance"); + require(IPoly(address(_polyToken)).decreaseApproval(_module, _change), "Insufficient allowance"); newAllowance = currentAllowance.sub(_change); } emit ModuleBudgetChanged(_modulesToData[_module].moduleTypes, _module, currentAllowance, newAllowance); @@ -325,7 +327,7 @@ library TokenLib { uint256 _value, uint256 _balanceTo, uint256 _balanceFrom, - address _dataStore + IDataStore _dataStore ) external returns(uint256) @@ -337,11 +339,10 @@ library TokenLib { // Check whether receiver is a new token holder if ((_balanceTo == 0) && (_to != address(0))) { holderCount = holderCount.add(1); - IDataStore dataStore = IDataStore(_dataStore); - if (!_isExistingInvestor(_to, dataStore)) { - dataStore.insertAddress(INVESTORSKEY, _to); + if (!_isExistingInvestor(_to, _dataStore)) { + _dataStore.insertAddress(INVESTORSKEY, _to); //KYC data can not be present if added is false and hence we can set packed KYC as uint256(1) to set added as true - dataStore.setUint256(_getKey(WHITELIST, _to), uint256(1)); + _dataStore.setUint256(_getKey(WHITELIST, _to), uint256(1)); } } // Check whether sender is moving all of their tokens diff --git a/contracts/mocks/Dummy/DummySTO.sol b/contracts/mocks/Dummy/DummySTO.sol index 22e5a7004..40a06b234 100644 --- a/contracts/mocks/Dummy/DummySTO.sol +++ b/contracts/mocks/Dummy/DummySTO.sol @@ -49,7 +49,7 @@ contract DummySTO is DummySTOStorage, STO { require(!paused, "Should not be paused"); require(_amount > 0, "Amount should be greater than 0"); require(_canBuy(_investor), "Unauthorized"); - ISecurityToken(securityToken).issue(_investor, _amount, ""); + securityToken.issue(_investor, _amount, ""); if (investors[_investor] == 0) { investorCount = investorCount + 1; } diff --git a/contracts/mocks/Dummy/DummySTOFactory.sol b/contracts/mocks/Dummy/DummySTOFactory.sol index 577091946..694b77b72 100644 --- a/contracts/mocks/Dummy/DummySTOFactory.sol +++ b/contracts/mocks/Dummy/DummySTOFactory.sol @@ -41,7 +41,7 @@ contract DummySTOFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address dummySTO = address(new DummySTOProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address dummySTO = address(new DummySTOProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(dummySTO, _data); return dummySTO; } diff --git a/contracts/mocks/MockBurnFactory.sol b/contracts/mocks/MockBurnFactory.sol index eaae590a3..a28c89af5 100644 --- a/contracts/mocks/MockBurnFactory.sol +++ b/contracts/mocks/MockBurnFactory.sol @@ -35,7 +35,7 @@ contract MockBurnFactory is TrackedRedemptionFactory { external returns(address) { - address mockRedemptionManager = address(new MockRedemptionManager(msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"))); + address mockRedemptionManager = address(new MockRedemptionManager(msg.sender, polymathRegistry.getAddress("PolyToken"))); _initializeModule(mockRedemptionManager, _data); return mockRedemptionManager; } diff --git a/contracts/mocks/MockRedemptionManager.sol b/contracts/mocks/MockRedemptionManager.sol index 9bcab6c44..bbd4af721 100644 --- a/contracts/mocks/MockRedemptionManager.sol +++ b/contracts/mocks/MockRedemptionManager.sol @@ -25,7 +25,7 @@ contract MockRedemptionManager is TrackedRedemption { * @param _value The number of tokens to redeem */ function transferToRedeem(uint256 _value) public { - require(ISecurityToken(securityToken).transferFrom(msg.sender, address(this), _value), "Insufficient funds"); + require(securityToken.transferFrom(msg.sender, address(this), _value), "Insufficient funds"); tokenToRedeem[msg.sender] = _value; } @@ -37,7 +37,7 @@ contract MockRedemptionManager is TrackedRedemption { require(tokenToRedeem[msg.sender] >= _value, "Insufficient tokens redeemable"); tokenToRedeem[msg.sender] = tokenToRedeem[msg.sender].sub(_value); redeemedTokens[msg.sender] = redeemedTokens[msg.sender].add(_value); - ISecurityToken(securityToken).redeem(_value, ""); + securityToken.redeem(_value, ""); /*solium-disable-next-line security/no-block-members*/ emit RedeemedTokenByOwner(msg.sender, address(this), _value); } @@ -52,7 +52,7 @@ contract MockRedemptionManager is TrackedRedemption { require(tokenToRedeem[msg.sender] >= _value, "Insufficient tokens redeemable"); tokenToRedeem[msg.sender] = tokenToRedeem[msg.sender].sub(_value); redeemedTokensByPartition[msg.sender][_partition] = redeemedTokensByPartition[msg.sender][_partition].add(_value); - ISecurityToken(securityToken).redeemByPartition(_partition, _value, _data); + securityToken.redeemByPartition(_partition, _value, _data); /*solium-disable-next-line security/no-block-members*/ emit RedeemedTokensByPartition(msg.sender, address(0), _partition, _value, _data, ""); } @@ -68,13 +68,13 @@ contract MockRedemptionManager is TrackedRedemption { require(tokenToRedeem[msg.sender] >= _value, "Insufficient tokens redeemable"); tokenToRedeem[msg.sender] = tokenToRedeem[msg.sender].sub(_value); redeemedTokensByPartition[msg.sender][_partition] = redeemedTokensByPartition[msg.sender][_partition].add(_value); - ISecurityToken(securityToken).operatorRedeemByPartition(_partition, msg.sender, _value, _data, _operatorData); + securityToken.operatorRedeemByPartition(_partition, msg.sender, _value, _data, _operatorData); /*solium-disable-next-line security/no-block-members*/ emit RedeemedTokensByPartition(msg.sender, address(this), _partition, _value, _data, _operatorData); } function operatorTransferToRedeem(uint256 _value, bytes32 _partition, bytes calldata _data, bytes calldata _operatorData) external { - ISecurityToken(securityToken).operatorTransferByPartition(_partition, msg.sender, address(this), _value, _data, _operatorData); + securityToken.operatorTransferByPartition(_partition, msg.sender, address(this), _value, _data, _operatorData); tokenToRedeem[msg.sender] = _value; } diff --git a/contracts/modules/Checkpoint/Dividend/DividendCheckpoint.sol b/contracts/modules/Checkpoint/Dividend/DividendCheckpoint.sol index dee07b225..ffa1513fd 100644 --- a/contracts/modules/Checkpoint/Dividend/DividendCheckpoint.sol +++ b/contracts/modules/Checkpoint/Dividend/DividendCheckpoint.sol @@ -94,7 +94,7 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module { * @return Checkpoint ID */ function createCheckpoint() public withPerm(OPERATOR) returns(uint256) { - return ISecurityToken(securityToken).createCheckpoint(); + return securityToken.createCheckpoint(); } /** @@ -182,7 +182,7 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module { _validDividendIndex(_dividendIndex); Dividend storage dividend = dividends[_dividendIndex]; uint256 checkpointId = dividend.checkpointId; - address[] memory investors = ISecurityToken(securityToken).getInvestorsSubsetAt(checkpointId, _start, _end); + address[] memory investors = securityToken.getInvestorsSubsetAt(checkpointId, _start, _end); // The investors list maybe smaller than _end - _start becuase it only contains addresses that had a positive balance // the _start and _end used here are for the address list stored in the dataStore for (uint256 i = 0; i < investors.length; i++) { @@ -231,7 +231,7 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module { if (dividend.claimed[_payee] || dividend.dividendExcluded[_payee]) { return (0, 0); } - uint256 balance = ISecurityToken(securityToken).balanceOfAt(_payee, dividend.checkpointId); + uint256 balance = securityToken.balanceOfAt(_payee, dividend.checkpointId); uint256 claim = balance.mul(dividend.amount).div(dividend.totalSupply); uint256 withheld = claim.mul(withholdingTax[_payee]).div(e18); return (claim, withheld); @@ -362,7 +362,7 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module { //Get list of Investors Dividend storage dividend = dividends[_dividendIndex]; uint256 checkpointId = dividend.checkpointId; - investors = ISecurityToken(securityToken).getInvestorsAt(checkpointId); + investors = securityToken.getInvestorsAt(checkpointId); resultClaimed = new bool[](investors.length); resultExcluded = new bool[](investors.length); resultWithheld = new uint256[](investors.length); @@ -371,7 +371,7 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module { for (uint256 i; i < investors.length; i++) { resultClaimed[i] = dividend.claimed[investors[i]]; resultExcluded[i] = dividend.dividendExcluded[investors[i]]; - resultBalance[i] = ISecurityToken(securityToken).balanceOfAt(investors[i], dividend.checkpointId); + resultBalance[i] = securityToken.balanceOfAt(investors[i], dividend.checkpointId); if (!resultExcluded[i]) { if (resultClaimed[i]) { resultWithheld[i] = dividend.withheld[investors[i]]; @@ -393,12 +393,12 @@ contract DividendCheckpoint is DividendCheckpointStorage, ICheckpoint, Module { * @return uint256[] investor withheld percentages */ function getCheckpointData(uint256 _checkpointId) external view returns (address[] memory investors, uint256[] memory balances, uint256[] memory withholdings) { - require(_checkpointId <= ISecurityToken(securityToken).currentCheckpointId(), "Invalid checkpoint"); - investors = ISecurityToken(securityToken).getInvestorsAt(_checkpointId); + require(_checkpointId <= securityToken.currentCheckpointId(), "Invalid checkpoint"); + investors = securityToken.getInvestorsAt(_checkpointId); balances = new uint256[](investors.length); withholdings = new uint256[](investors.length); for (uint256 i; i < investors.length; i++) { - balances[i] = ISecurityToken(securityToken).balanceOfAt(investors[i], _checkpointId); + balances[i] = securityToken.balanceOfAt(investors[i], _checkpointId); withholdings[i] = withholdingTax[investors[i]]; } } diff --git a/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpoint.sol b/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpoint.sol index 49fe186ef..af122ddba 100644 --- a/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpoint.sol +++ b/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpoint.sol @@ -103,7 +103,7 @@ contract ERC20DividendCheckpoint is ERC20DividendCheckpointStorage, DividendChec public withPerm(ADMIN) { - uint256 checkpointId = ISecurityToken(securityToken).createCheckpoint(); + uint256 checkpointId = securityToken.createCheckpoint(); _createDividendWithCheckpointAndExclusions(_maturity, _expiry, _token, _amount, checkpointId, _excluded, _name); } @@ -153,18 +153,18 @@ contract ERC20DividendCheckpoint is ERC20DividendCheckpointStorage, DividendChec ) internal { - ISecurityToken securityTokenInstance = ISecurityToken(securityToken); require(_excluded.length <= EXCLUDED_ADDRESS_LIMIT, "Too many addresses excluded"); require(_expiry > _maturity, "Expiry before maturity"); /*solium-disable-next-line security/no-block-members*/ require(_expiry > now, "Expiry in past"); require(_amount > 0, "No dividend sent"); require(_token != address(0), "Invalid token"); - require(_checkpointId <= securityTokenInstance.currentCheckpointId(), "Invalid checkpoint"); + require(_checkpointId <= securityToken.currentCheckpointId(), "Invalid checkpoint"); require(IERC20(_token).transferFrom(msg.sender, address(this), _amount), "insufficent allowance"); require(_name != bytes32(0)); uint256 dividendIndex = dividends.length; - uint256 currentSupply = securityTokenInstance.totalSupplyAt(_checkpointId); + uint256 currentSupply = securityToken.totalSupplyAt(_checkpointId); + require(currentSupply > 0, "Invalid supply"); uint256 excludedSupply = 0; dividends.push( Dividend( @@ -185,7 +185,7 @@ contract ERC20DividendCheckpoint is ERC20DividendCheckpointStorage, DividendChec for (uint256 j = 0; j < _excluded.length; j++) { require(_excluded[j] != address(0), "Invalid address"); require(!dividends[dividendIndex].dividendExcluded[_excluded[j]], "duped exclude address"); - excludedSupply = excludedSupply.add(securityTokenInstance.balanceOfAt(_excluded[j], _checkpointId)); + excludedSupply = excludedSupply.add(securityToken.balanceOfAt(_excluded[j], _checkpointId)); dividends[dividendIndex].dividendExcluded[_excluded[j]] = true; } require(currentSupply > excludedSupply, "Invalid supply"); diff --git a/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpointFactory.sol b/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpointFactory.sol index d6e9e7820..42a424001 100644 --- a/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpointFactory.sol +++ b/contracts/modules/Checkpoint/Dividend/ERC20/ERC20DividendCheckpointFactory.sol @@ -40,7 +40,7 @@ contract ERC20DividendCheckpointFactory is UpgradableModuleFactory { * @return Address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address erc20DividendCheckpoint = address(new ERC20DividendCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address erc20DividendCheckpoint = address(new ERC20DividendCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(erc20DividendCheckpoint, _data); return erc20DividendCheckpoint; } diff --git a/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpoint.sol b/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpoint.sol index e1e04539a..360f5dfe2 100644 --- a/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpoint.sol +++ b/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpoint.sol @@ -79,7 +79,7 @@ contract EtherDividendCheckpoint is DividendCheckpoint { payable withPerm(ADMIN) { - uint256 checkpointId = ISecurityToken(securityToken).createCheckpoint(); + uint256 checkpointId = securityToken.createCheckpoint(); _createDividendWithCheckpointAndExclusions(_maturity, _expiry, checkpointId, _excluded, _name); } @@ -127,10 +127,11 @@ contract EtherDividendCheckpoint is DividendCheckpoint { /*solium-disable-next-line security/no-block-members*/ require(_expiry > now, "Expiry is in the past"); require(msg.value > 0, "No dividend sent"); - require(_checkpointId <= ISecurityToken(securityToken).currentCheckpointId()); + require(_checkpointId <= securityToken.currentCheckpointId()); require(_name[0] != bytes32(0)); uint256 dividendIndex = dividends.length; - uint256 currentSupply = ISecurityToken(securityToken).totalSupplyAt(_checkpointId); + uint256 currentSupply = securityToken.totalSupplyAt(_checkpointId); + require(currentSupply > 0, "Invalid supply"); uint256 excludedSupply = 0; dividends.push( Dividend( @@ -151,7 +152,7 @@ contract EtherDividendCheckpoint is DividendCheckpoint { for (uint256 j = 0; j < _excluded.length; j++) { require(_excluded[j] != address(0), "Invalid address"); require(!dividends[dividendIndex].dividendExcluded[_excluded[j]], "duped exclude address"); - excludedSupply = excludedSupply.add(ISecurityToken(securityToken).balanceOfAt(_excluded[j], _checkpointId)); + excludedSupply = excludedSupply.add(securityToken.balanceOfAt(_excluded[j], _checkpointId)); dividends[dividendIndex].dividendExcluded[_excluded[j]] = true; } require(currentSupply > excludedSupply, "Invalid supply"); diff --git a/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpointFactory.sol b/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpointFactory.sol index 18f34b777..1d3239009 100644 --- a/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpointFactory.sol +++ b/contracts/modules/Checkpoint/Dividend/Ether/EtherDividendCheckpointFactory.sol @@ -40,7 +40,7 @@ contract EtherDividendCheckpointFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address ethDividendCheckpoint = address(new EtherDividendCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address ethDividendCheckpoint = address(new EtherDividendCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(ethDividendCheckpoint, _data); return ethDividendCheckpoint; } diff --git a/contracts/modules/Checkpoint/Voting/PLCR/PLCRVotingCheckpointFactory.sol b/contracts/modules/Checkpoint/Voting/PLCR/PLCRVotingCheckpointFactory.sol index d5ed40041..2ce4153ef 100644 --- a/contracts/modules/Checkpoint/Voting/PLCR/PLCRVotingCheckpointFactory.sol +++ b/contracts/modules/Checkpoint/Voting/PLCR/PLCRVotingCheckpointFactory.sol @@ -42,7 +42,7 @@ contract PLCRVotingCheckpointFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address plcrVotingCheckpoint = address(new PLCRVotingCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address plcrVotingCheckpoint = address(new PLCRVotingCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(plcrVotingCheckpoint, _data); return plcrVotingCheckpoint; } diff --git a/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpoint.sol b/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpoint.sol index a40558e3c..6dd575c7a 100644 --- a/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpoint.sol +++ b/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpoint.sol @@ -52,7 +52,7 @@ contract WeightedVoteCheckpoint is WeightedVoteCheckpointStorage, VotingCheckpoi */ function createBallot(uint256 _duration, uint256 _noOfProposals, uint256 _proposedQuorum) external withPerm(ADMIN) { require(_duration > 0, "Incorrect ballot duration"); - uint256 checkpointId = ISecurityToken(securityToken).createCheckpoint(); + uint256 checkpointId = securityToken.createCheckpoint(); uint256 endTime = now.add(_duration); _createCustomBallot(checkpointId, _proposedQuorum, now, endTime, _noOfProposals); } @@ -93,7 +93,7 @@ contract WeightedVoteCheckpoint is WeightedVoteCheckpointStorage, VotingCheckpoi * @param _noOfProposals Number of proposals */ function createCustomBallot(uint256 _checkpointId, uint256 _proposedQuorum, uint256 _startTime, uint256 _endTime, uint256 _noOfProposals) external withPerm(ADMIN) { - require(_checkpointId <= ISecurityToken(securityToken).currentCheckpointId(), "Invalid checkpoint Id"); + require(_checkpointId <= securityToken.currentCheckpointId(), "Invalid checkpoint Id"); require(_startTime >= now, "Invalid startTime"); _createCustomBallot(_checkpointId, _proposedQuorum, _startTime, _endTime, _noOfProposals); } @@ -107,7 +107,7 @@ contract WeightedVoteCheckpoint is WeightedVoteCheckpointStorage, VotingCheckpoi _validBallotId(_ballotId); Ballot storage ballot = ballots[_ballotId]; require(isVoterAllowed(_ballotId, msg.sender), "Invalid voter"); - uint256 weight = ISecurityToken(securityToken).balanceOfAt(msg.sender, ballot.checkpointId); + uint256 weight = securityToken.balanceOfAt(msg.sender, ballot.checkpointId); require(weight > 0, "weight should be > 0"); require(ballot.totalProposals >= _proposalId && _proposalId > 0, "Incorrect proposals Id"); require(now >= ballot.startTime && now <= ballot.endTime, "Voting period is not active"); @@ -198,7 +198,7 @@ contract WeightedVoteCheckpoint is WeightedVoteCheckpointStorage, VotingCheckpoi uint256 i; uint256 counter = 0; uint256 maxWeight = 0; - uint256 supplyAtCheckpoint = ISecurityToken(securityToken).totalSupplyAt(ballot.checkpointId); + uint256 supplyAtCheckpoint = securityToken.totalSupplyAt(ballot.checkpointId); uint256 quorumWeight = (supplyAtCheckpoint.mul(ballot.quorum)).div(10 ** 18); voteWeighting = new uint256[](ballot.totalProposals); for (i = 0; i < ballot.totalProposals; i++) { @@ -257,7 +257,7 @@ contract WeightedVoteCheckpoint is WeightedVoteCheckpointStorage, VotingCheckpoi Ballot memory ballot = ballots[_ballotId]; return ( ballot.quorum, - ISecurityToken(securityToken).totalSupplyAt(ballot.checkpointId), + securityToken.totalSupplyAt(ballot.checkpointId), ballot.checkpointId, ballot.startTime, ballot.endTime, diff --git a/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpointFactory.sol b/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpointFactory.sol index 8791845d7..54f8440f0 100644 --- a/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpointFactory.sol +++ b/contracts/modules/Checkpoint/Voting/Transparent/WeightedVoteCheckpointFactory.sol @@ -41,7 +41,7 @@ contract WeightedVoteCheckpointFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address weightedVoteCheckpoint = address(new WeightedVoteCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address weightedVoteCheckpoint = address(new WeightedVoteCheckpointProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(weightedVoteCheckpoint, _data); return weightedVoteCheckpoint; } diff --git a/contracts/modules/Experimental/Burn/TrackedRedemption.sol b/contracts/modules/Experimental/Burn/TrackedRedemption.sol index 7edf4809e..8e97fd6b2 100644 --- a/contracts/modules/Experimental/Burn/TrackedRedemption.sol +++ b/contracts/modules/Experimental/Burn/TrackedRedemption.sol @@ -34,7 +34,7 @@ contract TrackedRedemption is IBurn, Module { * @param _value The number of tokens to redeem */ function redeemTokens(uint256 _value) public { - ISecurityToken(securityToken).redeemFrom(msg.sender, _value, ""); + securityToken.redeemFrom(msg.sender, _value, ""); redeemedTokens[msg.sender] = redeemedTokens[msg.sender].add(_value); /*solium-disable-next-line security/no-block-members*/ emit Redeemed(msg.sender, _value); diff --git a/contracts/modules/Experimental/Burn/TrackedRedemptionFactory.sol b/contracts/modules/Experimental/Burn/TrackedRedemptionFactory.sol index 03e0f86f1..c31459288 100644 --- a/contracts/modules/Experimental/Burn/TrackedRedemptionFactory.sol +++ b/contracts/modules/Experimental/Burn/TrackedRedemptionFactory.sol @@ -41,7 +41,7 @@ contract TrackedRedemptionFactory is ModuleFactory { external returns(address) { - address trackedRedemption = address(new TrackedRedemption(msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"))); + address trackedRedemption = address(new TrackedRedemption(msg.sender, polymathRegistry.getAddress("PolyToken"))); _initializeModule(trackedRedemption, _data); return trackedRedemption; } diff --git a/contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol b/contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol index 67fb7b88c..78b21c85b 100644 --- a/contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol +++ b/contracts/modules/Experimental/Mixed/ScheduledCheckpoint.sol @@ -154,7 +154,7 @@ contract ScheduledCheckpoint is ICheckpoint, TransferManager { function _update(bytes32 _name) internal { Schedule storage schedule = schedules[_name]; if (schedule.nextTime <= now) { - uint256 checkpointId = ISecurityToken(securityToken).createCheckpoint(); + uint256 checkpointId = securityToken.createCheckpoint(); schedule.checkpointIds.push(checkpointId); schedule.timestamps.push(schedule.nextTime); uint256 periods; diff --git a/contracts/modules/Experimental/Mixed/ScheduledCheckpointFactory.sol b/contracts/modules/Experimental/Mixed/ScheduledCheckpointFactory.sol index 353f9a524..343641fba 100644 --- a/contracts/modules/Experimental/Mixed/ScheduledCheckpointFactory.sol +++ b/contracts/modules/Experimental/Mixed/ScheduledCheckpointFactory.sol @@ -42,7 +42,7 @@ contract ScheduledCheckpointFactory is ModuleFactory { external returns(address) { - address scheduledCheckpoint = address(new ScheduledCheckpoint(msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"))); + address scheduledCheckpoint = address(new ScheduledCheckpoint(msg.sender, polymathRegistry.getAddress("PolyToken"))); _initializeModule(scheduledCheckpoint, _data); return scheduledCheckpoint; } diff --git a/contracts/modules/Experimental/TransferManager/KYCTransferManagerFactory.sol b/contracts/modules/Experimental/TransferManager/KYCTransferManagerFactory.sol index cd4046127..14c319a71 100644 --- a/contracts/modules/Experimental/TransferManager/KYCTransferManagerFactory.sol +++ b/contracts/modules/Experimental/TransferManager/KYCTransferManagerFactory.sol @@ -34,7 +34,7 @@ contract KYCTransferManagerFactory is ModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address kycTransferManager = address(new KYCTransferManager(msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"))); + address kycTransferManager = address(new KYCTransferManager(msg.sender, polymathRegistry.getAddress("PolyToken"))); _initializeModule(kycTransferManager, _data); return kycTransferManager; } diff --git a/contracts/modules/Experimental/TransferManager/SignedTransferManagerFactory.sol b/contracts/modules/Experimental/TransferManager/SignedTransferManagerFactory.sol index 44e9d811c..eeb94baf6 100644 --- a/contracts/modules/Experimental/TransferManager/SignedTransferManagerFactory.sol +++ b/contracts/modules/Experimental/TransferManager/SignedTransferManagerFactory.sol @@ -36,7 +36,7 @@ contract SignedTransferManagerFactory is ModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address signedTransferManager = address(new SignedTransferManager(msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"))); + address signedTransferManager = address(new SignedTransferManager(msg.sender, polymathRegistry.getAddress("PolyToken"))); _initializeModule(signedTransferManager, _data); return signedTransferManager; } diff --git a/contracts/modules/Module.sol b/contracts/modules/Module.sol index 055408391..cd491d9f8 100644 --- a/contracts/modules/Module.sol +++ b/contracts/modules/Module.sol @@ -31,13 +31,13 @@ contract Module is IModule, ModuleStorage, Pausable { } function _checkPerm(bytes32 _perm, address _caller) internal view returns (bool) { - bool isOwner = _caller == Ownable(securityToken).owner(); + bool isOwner = _caller == Ownable(address(securityToken)).owner(); bool isFactory = _caller == factory; - return isOwner || isFactory || ICheckPermission(securityToken).checkPermission(_caller, address(this), _perm); + return isOwner || isFactory || ICheckPermission(address(securityToken)).checkPermission(_caller, address(this), _perm); } function _onlySecurityTokenOwner() internal view { - require(msg.sender == Ownable(securityToken).owner(), "Sender is not owner"); + require(msg.sender == Ownable(address(securityToken)).owner(), "Sender is not owner"); } modifier onlyFactory() { @@ -65,7 +65,7 @@ contract Module is IModule, ModuleStorage, Pausable { * @notice used to return the data store address of securityToken */ function getDataStore() public view returns(IDataStore) { - return IDataStore(ISecurityToken(securityToken).dataStore()); + return IDataStore(securityToken.dataStore()); } /** diff --git a/contracts/modules/ModuleFactory.sol b/contracts/modules/ModuleFactory.sol index 8f108fd56..7ed4dc24e 100644 --- a/contracts/modules/ModuleFactory.sol +++ b/contracts/modules/ModuleFactory.sol @@ -16,7 +16,7 @@ import "../libraries/DecimalMath.sol"; */ contract ModuleFactory is IModuleFactory, Ownable { - address public polymathRegistry; + IPolymathRegistry public polymathRegistry; string initialVersion; bytes32 public name; @@ -43,7 +43,7 @@ contract ModuleFactory is IModuleFactory, Ownable { */ constructor(uint256 _setupCost, address _polymathRegistry, bool _isCostInPoly) public { setupCost = _setupCost; - polymathRegistry = _polymathRegistry; + polymathRegistry = IPolymathRegistry(_polymathRegistry); isCostInPoly = _isCostInPoly; } @@ -172,7 +172,7 @@ contract ModuleFactory is IModuleFactory, Ownable { function setupCostInPoly() public returns (uint256) { if (isCostInPoly) return setupCost; - uint256 polyRate = IOracle(IPolymathRegistry(polymathRegistry).getAddress(POLY_ORACLE)).getPrice(); + uint256 polyRate = IOracle(polymathRegistry.getAddress(POLY_ORACLE)).getPrice(); return DecimalMath.div(setupCost, polyRate); } @@ -181,7 +181,7 @@ contract ModuleFactory is IModuleFactory, Ownable { */ function _takeFee() internal returns(uint256) { uint256 polySetupCost = setupCostInPoly(); - address polyToken = IPolymathRegistry(polymathRegistry).getAddress("PolyToken"); + address polyToken = polymathRegistry.getAddress("PolyToken"); if (polySetupCost > 0) { require(IERC20(polyToken).transferFrom(msg.sender, owner(), polySetupCost), "Insufficient allowance for module fee"); } diff --git a/contracts/modules/PermissionManager/GeneralPermissionManager.sol b/contracts/modules/PermissionManager/GeneralPermissionManager.sol index f19a8753d..bee4a3a3c 100644 --- a/contracts/modules/PermissionManager/GeneralPermissionManager.sol +++ b/contracts/modules/PermissionManager/GeneralPermissionManager.sol @@ -164,7 +164,7 @@ contract GeneralPermissionManager is GeneralPermissionManagerStorage, IPermissio uint256 counter = 0; // loop through _types and get their modules from securityToken->getModulesByType for (uint256 i = 0; i < _types.length; i++) { - address[] memory _currentTypeModules = ISecurityToken(securityToken).getModulesByType(_types[i]); + address[] memory _currentTypeModules = securityToken.getModulesByType(_types[i]); // loop through each modules to get their perms from IModule->getPermissions for (uint256 j = 0; j < _currentTypeModules.length; j++) { bytes32[] memory _allModulePerms = IModule(_currentTypeModules[j]).getPermissions(); @@ -182,7 +182,7 @@ contract GeneralPermissionManager is GeneralPermissionManagerStorage, IPermissio counter = 0; for (uint256 i = 0; i < _types.length; i++) { - address[] memory _currentTypeModules = ISecurityToken(securityToken).getModulesByType(_types[i]); + address[] memory _currentTypeModules = securityToken.getModulesByType(_types[i]); for (uint256 j = 0; j < _currentTypeModules.length; j++) { bytes32[] memory _allModulePerms = IModule(_currentTypeModules[j]).getPermissions(); for (uint256 k = 0; k < _allModulePerms.length; k++) { diff --git a/contracts/modules/PermissionManager/GeneralPermissionManagerFactory.sol b/contracts/modules/PermissionManager/GeneralPermissionManagerFactory.sol index e11bed8c1..d070696b1 100644 --- a/contracts/modules/PermissionManager/GeneralPermissionManagerFactory.sol +++ b/contracts/modules/PermissionManager/GeneralPermissionManagerFactory.sol @@ -43,7 +43,7 @@ contract GeneralPermissionManagerFactory is UpgradableModuleFactory { external returns(address) { - address permissionManager = address(new GeneralPermissionManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address permissionManager = address(new GeneralPermissionManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(permissionManager, _data); return permissionManager; } diff --git a/contracts/modules/STO/Capped/CappedSTO.sol b/contracts/modules/STO/Capped/CappedSTO.sol index 5d954e0de..3cf2ecc93 100644 --- a/contracts/modules/STO/Capped/CappedSTO.sol +++ b/contracts/modules/STO/Capped/CappedSTO.sol @@ -204,7 +204,7 @@ contract CappedSTO is CappedSTOStorage, STO, ReentrancyGuard { * @param _tokenAmount Number of tokens to be emitted */ function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal { - ISecurityToken(securityToken).issue(_beneficiary, _tokenAmount, ""); + securityToken.issue(_beneficiary, _tokenAmount, ""); } /** @@ -233,7 +233,7 @@ contract CappedSTO is CappedSTOStorage, STO, ReentrancyGuard { if (totalTokensSold.add(tokens) > cap) { tokens = cap.sub(totalTokensSold); } - uint256 granularity = ISecurityToken(securityToken).granularity(); + uint256 granularity = securityToken.granularity(); tokens = tokens.div(granularity); tokens = tokens.mul(granularity); require(tokens > 0, "Cap reached"); diff --git a/contracts/modules/STO/Capped/CappedSTOFactory.sol b/contracts/modules/STO/Capped/CappedSTOFactory.sol index 0d1dc8736..abed3ffc4 100644 --- a/contracts/modules/STO/Capped/CappedSTOFactory.sol +++ b/contracts/modules/STO/Capped/CappedSTOFactory.sol @@ -42,7 +42,7 @@ contract CappedSTOFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address cappedSTO = address(new CappedSTOProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address cappedSTO = address(new CappedSTOProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(cappedSTO, _data); return cappedSTO; } diff --git a/contracts/modules/STO/PreSale/PreSaleSTO.sol b/contracts/modules/STO/PreSale/PreSaleSTO.sol index 863127f47..c23190f3c 100644 --- a/contracts/modules/STO/PreSale/PreSaleSTO.sol +++ b/contracts/modules/STO/PreSale/PreSaleSTO.sol @@ -79,7 +79,7 @@ contract PreSaleSTO is PreSaleSTOStorage, STO { require(now <= endTime, "Already passed Endtime"); require(_amount > 0, "No. of tokens provided should be greater the zero"); require(_canBuy(_investor), "Unauthorized"); - ISecurityToken(securityToken).issue(_investor, _amount, ""); + securityToken.issue(_investor, _amount, ""); if (investors[_investor] == uint256(0)) { investorCount = investorCount.add(1); } diff --git a/contracts/modules/STO/PreSale/PreSaleSTOFactory.sol b/contracts/modules/STO/PreSale/PreSaleSTOFactory.sol index d6e5360f7..de2654276 100644 --- a/contracts/modules/STO/PreSale/PreSaleSTOFactory.sol +++ b/contracts/modules/STO/PreSale/PreSaleSTOFactory.sol @@ -40,7 +40,7 @@ contract PreSaleSTOFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address preSaleSTO = address(new PreSaleSTOProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address preSaleSTO = address(new PreSaleSTOProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(preSaleSTO, _data); return preSaleSTO; } diff --git a/contracts/modules/STO/USDTiered/USDTieredSTO.sol b/contracts/modules/STO/USDTiered/USDTieredSTO.sol index 23bd4c5d7..ab99ec905 100644 --- a/contracts/modules/STO/USDTiered/USDTieredSTO.sol +++ b/contracts/modules/STO/USDTiered/USDTieredSTO.sol @@ -40,7 +40,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { uint256 _rate ); event ReserveTokenMint(address indexed _owner, address indexed _wallet, uint256 _tokens, uint256 _latestTier); - event SetAddresses(address indexed _wallet, address[] _usdTokens); + event SetAddresses(address indexed _wallet, IERC20[] _usdTokens); event SetLimits(uint256 _nonAccreditedLimitUSD, uint256 _minimumInvestmentUSD); event SetTimes(uint256 _startTime, uint256 _endTime); event SetTiers( @@ -105,7 +105,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { FundRaiseType[] memory _fundRaiseTypes, address payable _wallet, address _treasuryWallet, - address[] memory _usdTokens + IERC20[] memory _usdTokens ) public onlyFactory @@ -181,7 +181,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { * @param _treasuryWallet Address of wallet where unsold tokens are sent * @param _usdTokens Address of usd tokens */ - function modifyAddresses(address payable _wallet, address _treasuryWallet, address[] calldata _usdTokens) external { + function modifyAddresses(address payable _wallet, address _treasuryWallet, IERC20[] calldata _usdTokens) external { _onlySecurityTokenOwner(); _modifyAddresses(_wallet, _treasuryWallet, _usdTokens); } @@ -242,7 +242,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { emit SetTimes(_startTime, _endTime); } - function _modifyAddresses(address payable _wallet, address _treasuryWallet, address[] memory _usdTokens) internal { + function _modifyAddresses(address payable _wallet, address _treasuryWallet, IERC20[] memory _usdTokens) internal { require(_wallet != address(0), "Invalid wallet"); wallet = _wallet; emit SetTreasuryWallet(treasuryWallet, _treasuryWallet); @@ -250,15 +250,15 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { _modifyUSDTokens(_usdTokens); } - function _modifyUSDTokens(address[] memory _usdTokens) internal { + function _modifyUSDTokens(IERC20[] memory _usdTokens) internal { uint256 i; for(i = 0; i < usdTokens.length; i++) { - usdTokenEnabled[usdTokens[i]] = false; + usdTokenEnabled[address(usdTokens[i])] = false; } usdTokens = _usdTokens; for(i = 0; i < _usdTokens.length; i++) { - require(_usdTokens[i] != address(0) && _usdTokens[i] != address(polyToken), "Invalid USD token"); - usdTokenEnabled[_usdTokens[i]] = true; + require(address(_usdTokens[i]) != address(0) && _usdTokens[i] != polyToken, "Invalid USD token"); + usdTokenEnabled[address(_usdTokens[i])] = true; } emit SetAddresses(wallet, _usdTokens); } @@ -287,10 +287,10 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { } address walletAddress = (treasuryWallet == address(0) ? IDataStore(getDataStore()).getAddress(TREASURY) : treasuryWallet); require(walletAddress != address(0), "Invalid address"); - uint256 granularity = ISecurityToken(securityToken).granularity(); + uint256 granularity = securityToken.granularity(); tempReturned = tempReturned.div(granularity); tempReturned = tempReturned.mul(granularity); - ISecurityToken(securityToken).issue(walletAddress, tempReturned, ""); + securityToken.issue(walletAddress, tempReturned, ""); emit ReserveTokenMint(msg.sender, walletAddress, tempReturned, currentTier); finalAmountReturned = tempReturned; totalTokensSold = tempSold; @@ -549,7 +549,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { returns(uint256 spentUSD, uint256 purchasedTokens, bool gotoNextTier) { purchasedTokens = DecimalMath.div(_investedUSD, _tierPrice); - uint256 granularity = ISecurityToken(securityToken).granularity(); + uint256 granularity = securityToken.granularity(); if (purchasedTokens > _tierRemaining) { purchasedTokens = _tierRemaining.div(granularity); @@ -567,7 +567,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { } if (purchasedTokens > 0) { - ISecurityToken(securityToken).issue(_beneficiary, purchasedTokens, ""); + securityToken.issue(_beneficiary, purchasedTokens, ""); emit TokenPurchase(msg.sender, _beneficiary, purchasedTokens, spentUSD, _tierPrice, _tier); } } @@ -712,7 +712,7 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { * @notice Return the usd tokens accepted by the STO * @return address[] usd tokens */ - function getUsdTokens() external view returns (address[] memory) { + function getUsdTokens() external view returns (IERC20[] memory) { return usdTokens; } @@ -773,6 +773,6 @@ contract USDTieredSTO is USDTieredSTOStorage, STO { function _getOracle(bytes32 _currency, bytes32 _denominatedCurrency) internal view returns(address oracleAddress) { oracleAddress = customOracles[_currency][_denominatedCurrency]; if (oracleAddress == address(0)) - oracleAddress = IPolymathRegistry(ISecurityToken(securityToken).polymathRegistry()).getAddress(oracleKeys[_currency][_denominatedCurrency]); + oracleAddress = IPolymathRegistry(securityToken.polymathRegistry()).getAddress(oracleKeys[_currency][_denominatedCurrency]); } } diff --git a/contracts/modules/STO/USDTiered/USDTieredSTOFactory.sol b/contracts/modules/STO/USDTiered/USDTieredSTOFactory.sol index 95263cede..7d55a2632 100644 --- a/contracts/modules/STO/USDTiered/USDTieredSTOFactory.sol +++ b/contracts/modules/STO/USDTiered/USDTieredSTOFactory.sol @@ -43,7 +43,7 @@ contract USDTieredSTOFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address usdTieredSTO = address(new USDTieredSTOProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address usdTieredSTO = address(new USDTieredSTOProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(usdTieredSTO, _data); return usdTieredSTO; } diff --git a/contracts/modules/STO/USDTiered/USDTieredSTOStorage.sol b/contracts/modules/STO/USDTiered/USDTieredSTOStorage.sol index 7281861fa..f5db99ad5 100644 --- a/contracts/modules/STO/USDTiered/USDTieredSTOStorage.sol +++ b/contracts/modules/STO/USDTiered/USDTieredSTOStorage.sol @@ -1,5 +1,7 @@ pragma solidity 0.5.8; +import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; + /** * @title Contract used to store layout for the USDTieredSTO storage */ @@ -42,7 +44,7 @@ contract USDTieredSTOStorage { address public treasuryWallet; // List of stable coin addresses - address[] internal usdTokens; + IERC20[] internal usdTokens; // Current tier uint256 public currentTier; diff --git a/contracts/modules/TransferManager/BTM/BlacklistTransferManager.sol b/contracts/modules/TransferManager/BTM/BlacklistTransferManager.sol index a797b6779..e66a3a22c 100644 --- a/contracts/modules/TransferManager/BTM/BlacklistTransferManager.sol +++ b/contracts/modules/TransferManager/BTM/BlacklistTransferManager.sol @@ -440,7 +440,7 @@ contract BlacklistTransferManager is BlacklistTransferManagerStorage, TransferMa * @param _additionalBalance It is the `_value` that transfer during transfer/transferFrom function call */ function getTokensByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) external view returns(uint256) { - uint256 currentBalance = (msg.sender == securityToken) ? (IERC20(securityToken).balanceOf(_tokenHolder)).add(_additionalBalance) : IERC20(securityToken).balanceOf(_tokenHolder); + uint256 currentBalance = (msg.sender == address(securityToken)) ? (securityToken.balanceOf(_tokenHolder)).add(_additionalBalance) : securityToken.balanceOf(_tokenHolder); if (paused && _partition == UNLOCKED) return currentBalance; diff --git a/contracts/modules/TransferManager/BTM/BlacklistTransferManagerFactory.sol b/contracts/modules/TransferManager/BTM/BlacklistTransferManagerFactory.sol index cfca66eba..2d9216d7c 100644 --- a/contracts/modules/TransferManager/BTM/BlacklistTransferManagerFactory.sol +++ b/contracts/modules/TransferManager/BTM/BlacklistTransferManagerFactory.sol @@ -39,7 +39,7 @@ contract BlacklistTransferManagerFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address blacklistTransferManager = address(new BlacklistTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address blacklistTransferManager = address(new BlacklistTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(blacklistTransferManager, _data); return blacklistTransferManager; } diff --git a/contracts/modules/TransferManager/CTM/CountTransferManager.sol b/contracts/modules/TransferManager/CTM/CountTransferManager.sol index 6b244d5af..30e86850b 100644 --- a/contracts/modules/TransferManager/CTM/CountTransferManager.sol +++ b/contracts/modules/TransferManager/CTM/CountTransferManager.sol @@ -66,9 +66,9 @@ contract CountTransferManager is CountTransferManagerStorage, TransferManager { returns(Result, bytes32) { if (!paused) { - if (maxHolderCount < ISecurityToken(securityToken).holderCount()) { + if (maxHolderCount < securityToken.holderCount()) { // Allow transfers to existing maxHolders - if (ISecurityToken(securityToken).balanceOf(_to) != 0 || ISecurityToken(securityToken).balanceOf(_from) == _amount) { + if (securityToken.balanceOf(_to) != 0 || securityToken.balanceOf(_from) == _amount) { return (Result.NA, bytes32(0)); } return (Result.INVALID, bytes32(uint256(address(this)) << 96)); diff --git a/contracts/modules/TransferManager/CTM/CountTransferManagerFactory.sol b/contracts/modules/TransferManager/CTM/CountTransferManagerFactory.sol index d0d5ab065..878304272 100644 --- a/contracts/modules/TransferManager/CTM/CountTransferManagerFactory.sol +++ b/contracts/modules/TransferManager/CTM/CountTransferManagerFactory.sol @@ -40,7 +40,7 @@ contract CountTransferManagerFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address countTransferManager = address(new CountTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address countTransferManager = address(new CountTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(countTransferManager, _data); return countTransferManager; } diff --git a/contracts/modules/TransferManager/GTM/GeneralTransferManager.sol b/contracts/modules/TransferManager/GTM/GeneralTransferManager.sol index 1cada4165..607ab2d7c 100644 --- a/contracts/modules/TransferManager/GTM/GeneralTransferManager.sol +++ b/contracts/modules/TransferManager/GTM/GeneralTransferManager.sol @@ -686,7 +686,7 @@ contract GeneralTransferManager is GeneralTransferManagerStorage, TransferManage * @param _additionalBalance It is the `_value` that transfer during transfer/transferFrom function call */ function getTokensByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) external view returns(uint256) { - uint256 currentBalance = (msg.sender == securityToken) ? (IERC20(securityToken).balanceOf(_tokenHolder)).add(_additionalBalance) : IERC20(securityToken).balanceOf(_tokenHolder); + uint256 currentBalance = (msg.sender == address(securityToken)) ? (securityToken.balanceOf(_tokenHolder)).add(_additionalBalance) : securityToken.balanceOf(_tokenHolder); uint256 canSendAfter; (canSendAfter,,,) = _getKYCValues(_tokenHolder, getDataStore()); canSendAfter = (canSendAfter == 0 ? defaults.canSendAfter: canSendAfter); diff --git a/contracts/modules/TransferManager/GTM/GeneralTransferManagerFactory.sol b/contracts/modules/TransferManager/GTM/GeneralTransferManagerFactory.sol index ee8524feb..606f334fc 100644 --- a/contracts/modules/TransferManager/GTM/GeneralTransferManagerFactory.sol +++ b/contracts/modules/TransferManager/GTM/GeneralTransferManagerFactory.sol @@ -45,7 +45,7 @@ contract GeneralTransferManagerFactory is UpgradableModuleFactory { external returns(address) { - address generalTransferManager = address(new GeneralTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address generalTransferManager = address(new GeneralTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(generalTransferManager, _data); return generalTransferManager; } diff --git a/contracts/modules/TransferManager/LTM/LockUpTransferManager.sol b/contracts/modules/TransferManager/LTM/LockUpTransferManager.sol index 123a67e34..d8a0d7855 100644 --- a/contracts/modules/TransferManager/LTM/LockUpTransferManager.sol +++ b/contracts/modules/TransferManager/LTM/LockUpTransferManager.sol @@ -456,7 +456,7 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager function _checkIfValidTransfer(address _userAddress, uint256 _amount) internal view returns (Result, bytes32) { uint256 totalRemainingLockedAmount = getLockedTokenToUser(_userAddress); // Present balance of the user - uint256 currentBalance = IERC20(securityToken).balanceOf(_userAddress); + uint256 currentBalance = securityToken.balanceOf(_userAddress); if ((currentBalance.sub(_amount)) >= totalRemainingLockedAmount) { return (Result.NA, bytes32(0)); } @@ -684,7 +684,7 @@ contract LockUpTransferManager is LockUpTransferManagerStorage, TransferManager * @param _additionalBalance It is the `_value` that transfer during transfer/transferFrom function call */ function getTokensByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) external view returns(uint256){ - uint256 currentBalance = (msg.sender == securityToken) ? (IERC20(securityToken).balanceOf(_tokenHolder)).add(_additionalBalance) : IERC20(securityToken).balanceOf(_tokenHolder); + uint256 currentBalance = (msg.sender == address(securityToken)) ? (securityToken.balanceOf(_tokenHolder)).add(_additionalBalance) : securityToken.balanceOf(_tokenHolder); uint256 lockedBalance = Math.min(getLockedTokenToUser(_tokenHolder), currentBalance); if (paused) { return (_partition == UNLOCKED ? currentBalance : uint256(0)); diff --git a/contracts/modules/TransferManager/LTM/LockUpTransferManagerFactory.sol b/contracts/modules/TransferManager/LTM/LockUpTransferManagerFactory.sol index 472daaf38..913436884 100644 --- a/contracts/modules/TransferManager/LTM/LockUpTransferManagerFactory.sol +++ b/contracts/modules/TransferManager/LTM/LockUpTransferManagerFactory.sol @@ -44,7 +44,7 @@ contract LockUpTransferManagerFactory is UpgradableModuleFactory { external returns(address) { - address lockUpTransferManager = address(new LockUpTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address lockUpTransferManager = address(new LockUpTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(lockUpTransferManager, _data); return lockUpTransferManager; } diff --git a/contracts/modules/TransferManager/MATM/ManualApprovalTransferManagerFactory.sol b/contracts/modules/TransferManager/MATM/ManualApprovalTransferManagerFactory.sol index 8df186320..2d9cdf8ec 100644 --- a/contracts/modules/TransferManager/MATM/ManualApprovalTransferManagerFactory.sol +++ b/contracts/modules/TransferManager/MATM/ManualApprovalTransferManagerFactory.sol @@ -44,7 +44,7 @@ contract ManualApprovalTransferManagerFactory is UpgradableModuleFactory { external returns(address) { - address manualTransferManager = address(new ManualApprovalTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address manualTransferManager = address(new ManualApprovalTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(manualTransferManager, _data); return manualTransferManager; } diff --git a/contracts/modules/TransferManager/PTM/PercentageTransferManager.sol b/contracts/modules/TransferManager/PTM/PercentageTransferManager.sol index f4efd9802..1a28969e1 100644 --- a/contracts/modules/TransferManager/PTM/PercentageTransferManager.sol +++ b/contracts/modules/TransferManager/PTM/PercentageTransferManager.sol @@ -86,8 +86,8 @@ contract PercentageTransferManager is PercentageTransferManagerStorage, Transfer if (whitelist[_to]) { return (Result.NA, bytes32(0)); } - uint256 newBalance = IERC20(securityToken).balanceOf(_to).add(_amount); - if (newBalance.mul(uint256(10) ** 18).div(IERC20(securityToken).totalSupply()) > maxHolderPercentage) { + uint256 newBalance = securityToken.balanceOf(_to).add(_amount); + if (newBalance.mul(uint256(10) ** 18).div(securityToken.totalSupply()) > maxHolderPercentage) { return (Result.INVALID, bytes32(uint256(address(this)) << 96)); } return (Result.NA, bytes32(0)); diff --git a/contracts/modules/TransferManager/PTM/PercentageTransferManagerFactory.sol b/contracts/modules/TransferManager/PTM/PercentageTransferManagerFactory.sol index e2fa7c75f..ba2c0684a 100644 --- a/contracts/modules/TransferManager/PTM/PercentageTransferManagerFactory.sol +++ b/contracts/modules/TransferManager/PTM/PercentageTransferManagerFactory.sol @@ -40,7 +40,7 @@ contract PercentageTransferManagerFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address percentageTransferManager = address(new PercentageTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address percentageTransferManager = address(new PercentageTransferManagerProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(percentageTransferManager, _data); return percentageTransferManager; } diff --git a/contracts/modules/TransferManager/TransferManager.sol b/contracts/modules/TransferManager/TransferManager.sol index c6f082412..54607cca5 100644 --- a/contracts/modules/TransferManager/TransferManager.sol +++ b/contracts/modules/TransferManager/TransferManager.sol @@ -12,7 +12,7 @@ contract TransferManager is ITransferManager, Module { bytes32 public constant UNLOCKED = "UNLOCKED"; modifier onlySecurityToken() { - require(msg.sender == securityToken, "Sender is not owner"); + require(msg.sender == address(securityToken), "Sender is not owner"); _; } diff --git a/contracts/modules/TransferManager/VRTM/VolumeRestrictionTM.sol b/contracts/modules/TransferManager/VRTM/VolumeRestrictionTM.sol index b66b1ae38..c2c229342 100644 --- a/contracts/modules/TransferManager/VRTM/VolumeRestrictionTM.sol +++ b/contracts/modules/TransferManager/VRTM/VolumeRestrictionTM.sol @@ -968,7 +968,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, TransferManager { { uint256 _allowedAmount = 0; if (_restriction.typeOfRestriction == RestrictionType.Percentage) { - _allowedAmount = (_restriction.allowedTokens.mul(IERC20(securityToken).totalSupply())) / uint256(10) ** 18; + _allowedAmount = (_restriction.allowedTokens.mul(securityToken.totalSupply())) / uint256(10) ** 18; } else { _allowedAmount = _restriction.allowedTokens; } @@ -1093,7 +1093,7 @@ contract VolumeRestrictionTM is VolumeRestrictionTMStorage, TransferManager { uint256 allowedAmountToTransact; uint256 fromTimestamp; uint256 dailyTime; - uint256 currentBalance = (msg.sender == securityToken) ? (IERC20(securityToken).balanceOf(_tokenHolder)).add(_additionalBalance) : IERC20(securityToken).balanceOf(_tokenHolder); + uint256 currentBalance = (msg.sender == address(securityToken)) ? (securityToken.balanceOf(_tokenHolder)).add(_additionalBalance) : securityToken.balanceOf(_tokenHolder); if (paused) return (_partition == UNLOCKED ? currentBalance: 0); diff --git a/contracts/modules/TransferManager/VRTM/VolumeRestrictionTMFactory.sol b/contracts/modules/TransferManager/VRTM/VolumeRestrictionTMFactory.sol index 09356504b..25a92ffdb 100644 --- a/contracts/modules/TransferManager/VRTM/VolumeRestrictionTMFactory.sol +++ b/contracts/modules/TransferManager/VRTM/VolumeRestrictionTMFactory.sol @@ -41,7 +41,7 @@ contract VolumeRestrictionTMFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address volumeRestrictionTransferManager = address(new VolumeRestrictionTMProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address volumeRestrictionTransferManager = address(new VolumeRestrictionTMProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(volumeRestrictionTransferManager, _data); return volumeRestrictionTransferManager; } diff --git a/contracts/modules/UpgradableModuleFactory.sol b/contracts/modules/UpgradableModuleFactory.sol index faa798c34..f09d467fd 100644 --- a/contracts/modules/UpgradableModuleFactory.sol +++ b/contracts/modules/UpgradableModuleFactory.sol @@ -94,7 +94,7 @@ contract UpgradableModuleFactory is ModuleFactory { logicContracts[_upgrade].version = _version; logicContracts[_upgrade].logicContract = _logicContract; logicContracts[_upgrade].upgradeData = _upgradeData; - IModuleRegistry moduleRegistry = IModuleRegistry(IPolymathRegistry(polymathRegistry).getAddress("ModuleRegistry")); + IModuleRegistry moduleRegistry = IModuleRegistry(polymathRegistry.getAddress("ModuleRegistry")); moduleRegistry.unverifyModule(address(this)); emit LogicContractSet(_version, _upgrade, _logicContract, _upgradeData); } diff --git a/contracts/modules/Wallet/VestingEscrowWallet.sol b/contracts/modules/Wallet/VestingEscrowWallet.sol index e261c11cf..3fe28d1ec 100644 --- a/contracts/modules/Wallet/VestingEscrowWallet.sol +++ b/contracts/modules/Wallet/VestingEscrowWallet.sol @@ -93,7 +93,7 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet { function _depositTokens(uint256 _numberOfTokens) internal { require(_numberOfTokens > 0, "Should be > 0"); require( - ISecurityToken(securityToken).transferFrom(msg.sender, address(this), _numberOfTokens), + securityToken.transferFrom(msg.sender, address(this), _numberOfTokens), "Failed transferFrom" ); unassignedTokens = unassignedTokens.add(_numberOfTokens); @@ -108,7 +108,7 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet { require(_amount > 0, "Amount cannot be zero"); require(_amount <= unassignedTokens, "Amount is greater than unassigned tokens"); unassignedTokens = unassignedTokens - _amount; - require(ISecurityToken(securityToken).transfer(getTreasuryWallet(), _amount), "Transfer failed"); + require(securityToken.transfer(getTreasuryWallet(), _amount), "Transfer failed"); emit SendToTreasury(_amount, msg.sender); } @@ -547,7 +547,7 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet { uint256 periodCount = _duration.div(_frequency); require(_numberOfTokens % periodCount == 0); uint256 amountPerPeriod = _numberOfTokens.div(periodCount); - require(amountPerPeriod % ISecurityToken(securityToken).granularity() == 0, "Invalid granularity"); + require(amountPerPeriod % securityToken.granularity() == 0, "Invalid granularity"); } function _sendTokens(address _beneficiary) internal { @@ -560,7 +560,7 @@ contract VestingEscrowWallet is VestingEscrowWalletStorage, Wallet { uint256 amount = _getAvailableTokens(_beneficiary, _index); if (amount > 0) { schedules[_beneficiary][_index].claimedTokens = schedules[_beneficiary][_index].claimedTokens.add(amount); - require(ISecurityToken(securityToken).transfer(_beneficiary, amount), "Transfer failed"); + require(securityToken.transfer(_beneficiary, amount), "Transfer failed"); emit SendTokens(_beneficiary, amount); } } diff --git a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol index 826aed25c..725de9e08 100644 --- a/contracts/modules/Wallet/VestingEscrowWalletFactory.sol +++ b/contracts/modules/Wallet/VestingEscrowWalletFactory.sol @@ -37,7 +37,7 @@ contract VestingEscrowWalletFactory is UpgradableModuleFactory { * @return address Contract address of the Module */ function deploy(bytes calldata _data) external returns(address) { - address vestingEscrowWallet = address(new VestingEscrowWalletProxy(logicContracts[latestUpgrade].version, msg.sender, IPolymathRegistry(polymathRegistry).getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); + address vestingEscrowWallet = address(new VestingEscrowWalletProxy(logicContracts[latestUpgrade].version, msg.sender, polymathRegistry.getAddress("PolyToken"), logicContracts[latestUpgrade].logicContract)); _initializeModule(vestingEscrowWallet, _data); return vestingEscrowWallet; } diff --git a/contracts/oracles/MakerDAOOracle.sol b/contracts/oracles/MakerDAOOracle.sol index 71661e446..1db3d956b 100644 --- a/contracts/oracles/MakerDAOOracle.sol +++ b/contracts/oracles/MakerDAOOracle.sol @@ -5,7 +5,7 @@ import "../external/IMedianizer.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; contract MakerDAOOracle is IOracle, Ownable { - address public medianizer; + IMedianizer public medianizer; address public currencyAddress; bytes32 public currencySymbol; @@ -24,7 +24,7 @@ contract MakerDAOOracle is IOracle, Ownable { * @param _currencySymbol Symbol of currency */ constructor(address _medianizer, address _currencyAddress, bytes32 _currencySymbol) public { - medianizer = _medianizer; + medianizer = IMedianizer(_medianizer); currencyAddress = _currencyAddress; currencySymbol = _currencySymbol; } @@ -36,8 +36,8 @@ contract MakerDAOOracle is IOracle, Ownable { function changeMedianier(address _medianizer) public onlyOwner { require(_medianizer != address(0), "0x not allowed"); /*solium-disable-next-line security/no-block-members*/ - emit ChangeMedianizer(_medianizer, medianizer); - medianizer = _medianizer; + emit ChangeMedianizer(_medianizer, address(medianizer)); + medianizer = IMedianizer(_medianizer); } /** @@ -69,7 +69,7 @@ contract MakerDAOOracle is IOracle, Ownable { if (manualOverride) { return manualPrice; } - (bytes32 price, bool valid) = IMedianizer(medianizer).peek(); + (bytes32 price, bool valid) = medianizer.peek(); require(valid, "MakerDAO Oracle returning invalid value"); return uint256(price); } diff --git a/contracts/storage/modules/ModuleStorage.sol b/contracts/storage/modules/ModuleStorage.sol index 3f8c67ff0..9e34f16df 100644 --- a/contracts/storage/modules/ModuleStorage.sol +++ b/contracts/storage/modules/ModuleStorage.sol @@ -1,6 +1,7 @@ pragma solidity 0.5.8; import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; +import "../../interfaces/ISecurityToken.sol"; /** * @title Storage for Module contract * @notice Contract is abstract @@ -8,7 +9,7 @@ import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; contract ModuleStorage { address public factory; - address public securityToken; + ISecurityToken public securityToken; // Permission flag bytes32 public constant ADMIN = "ADMIN"; @@ -24,7 +25,7 @@ contract ModuleStorage { * @param _polyAddress Address of the polytoken */ constructor(address _securityToken, address _polyAddress) public { - securityToken = _securityToken; + securityToken = ISecurityToken(_securityToken); factory = msg.sender; polyToken = IERC20(_polyAddress); } diff --git a/contracts/tokens/STGetter.sol b/contracts/tokens/STGetter.sol index efea1793a..d4810d948 100644 --- a/contracts/tokens/STGetter.sol +++ b/contracts/tokens/STGetter.sol @@ -3,7 +3,6 @@ pragma solidity 0.5.8; import "./OZStorage.sol"; import "./SecurityTokenStorage.sol"; import "../libraries/TokenLib.sol"; -import "../interfaces/IDataStore.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../modules/PermissionManager/IPermissionManager.sol"; @@ -35,8 +34,7 @@ contract STGetter is OZStorage, SecurityTokenStorage { * @return Investor count */ function getInvestorCount() external view returns(uint256) { - IDataStore dataStoreInstance = IDataStore(dataStore); - return dataStoreInstance.getAddressArrayLength(INVESTORSKEY); + return dataStore.getAddressArrayLength(INVESTORSKEY); } /** @@ -45,8 +43,7 @@ contract STGetter is OZStorage, SecurityTokenStorage { * @return list of addresses */ function getInvestors() public view returns(address[] memory investors) { - IDataStore dataStoreInstance = IDataStore(dataStore); - investors = dataStoreInstance.getAddressArray(INVESTORSKEY); + investors = dataStore.getAddressArray(INVESTORSKEY); } /** @@ -57,8 +54,7 @@ contract STGetter is OZStorage, SecurityTokenStorage { function getInvestorsAt(uint256 _checkpointId) external view returns(address[] memory) { uint256 count; uint256 i; - IDataStore dataStoreInstance = IDataStore(dataStore); - address[] memory investors = dataStoreInstance.getAddressArray(INVESTORSKEY); + address[] memory investors = dataStore.getAddressArray(INVESTORSKEY); for (i = 0; i < investors.length; i++) { if (balanceOfAt(investors[i], _checkpointId) > 0) { count++; @@ -87,8 +83,7 @@ contract STGetter is OZStorage, SecurityTokenStorage { function getInvestorsSubsetAt(uint256 _checkpointId, uint256 _start, uint256 _end) external view returns(address[] memory) { uint256 count; uint256 i; - IDataStore dataStoreInstance = IDataStore(dataStore); - address[] memory investors = dataStoreInstance.getAddressArrayElements(INVESTORSKEY, _start, _end); + address[] memory investors = dataStore.getAddressArrayElements(INVESTORSKEY, _start, _end); for (i = 0; i < investors.length; i++) { if (balanceOfAt(investors[i], _checkpointId) > 0) { count++; @@ -150,7 +145,7 @@ contract STGetter is OZStorage, SecurityTokenStorage { * @notice use to return the global treasury wallet */ function getTreasuryWallet() external view returns(address) { - return IDataStore(dataStore).getAddress(TREASURY); + return dataStore.getAddress(TREASURY); } /** @@ -181,8 +176,7 @@ contract STGetter is OZStorage, SecurityTokenStorage { * @return list of investors */ function iterateInvestors(uint256 _start, uint256 _end) external view returns(address[] memory) { - IDataStore dataStoreInstance = IDataStore(dataStore); - return dataStoreInstance.getAddressArrayElements(INVESTORSKEY, _start, _end); + return dataStore.getAddressArrayElements(INVESTORSKEY, _start, _end); } /** diff --git a/contracts/tokens/SecurityToken.sol b/contracts/tokens/SecurityToken.sol index 9bcfb8441..26ee2b7ef 100644 --- a/contracts/tokens/SecurityToken.sol +++ b/contracts/tokens/SecurityToken.sol @@ -1,7 +1,6 @@ pragma solidity 0.5.8; import "../proxy/Proxy.sol"; -import "../PolymathRegistry.sol"; import "../interfaces/IModule.sol"; import "./SecurityTokenStorage.sol"; import "../libraries/TokenLib.sol"; @@ -13,7 +12,6 @@ import "../interfaces/token/IERC1410.sol"; import "../interfaces/token/IERC1594.sol"; import "../interfaces/token/IERC1643.sol"; import "../interfaces/token/IERC1644.sol"; -import "../interfaces/IModuleRegistry.sol"; import "../interfaces/ITransferManager.sol"; import "openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol"; import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; @@ -198,18 +196,18 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594 { _onlyOwner(); //Check that the module factory exists in the ModuleRegistry - will throw otherwise - IModuleRegistry(moduleRegistry).useModule(_moduleFactory, false); + moduleRegistry.useModule(_moduleFactory, false); IModuleFactory moduleFactory = IModuleFactory(_moduleFactory); uint8[] memory moduleTypes = moduleFactory.types(); uint256 moduleCost = moduleFactory.setupCostInPoly(); require(moduleCost <= _maxCost, "Invalid cost"); //Approve fee for module - ERC20(polyToken).approve(_moduleFactory, moduleCost); + polyToken.approve(_moduleFactory, moduleCost); //Creates instance of module from factory address module = moduleFactory.deploy(_data); require(modulesToData[module].module == address(0), "Module exists"); //Approve ongoing budget - ERC20(polyToken).approve(module, _budget); + polyToken.approve(module, _budget); _addModuleData(moduleTypes, _moduleFactory, module, moduleCost, _budget, _label, _archived); } @@ -350,7 +348,7 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594 function changeDataStore(address _dataStore) external { _onlyOwner(); _zeroAddressCheck(_dataStore); - dataStore = _dataStore; + dataStore = IDataStore(_dataStore); } /** @@ -371,8 +369,8 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594 function changeTreasuryWallet(address _wallet) external { _onlyOwner(); _zeroAddressCheck(_wallet); - emit TreasuryWalletChanged(IDataStore(dataStore).getAddress(TREASURY), _wallet); - IDataStore(dataStore).setAddress(TREASURY, _wallet); + emit TreasuryWalletChanged(dataStore.getAddress(TREASURY), _wallet); + dataStore.setAddress(TREASURY, _wallet); } /** @@ -873,13 +871,12 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594 */ function createCheckpoint() external returns(uint256) { _onlyModuleOrOwner(CHECKPOINT_KEY); - IDataStore dataStoreInstance = IDataStore(dataStore); // currentCheckpointId can only be incremented by 1 and hence it can not be overflowed currentCheckpointId = currentCheckpointId + 1; /*solium-disable-next-line security/no-block-members*/ checkpointTimes.push(now); checkpointTotalSupply[currentCheckpointId] = totalSupply(); - emit CheckpointCreated(currentCheckpointId, dataStoreInstance.getAddressArrayLength(INVESTORSKEY)); + emit CheckpointCreated(currentCheckpointId, dataStore.getAddressArrayLength(INVESTORSKEY)); return currentCheckpointId; } @@ -1064,9 +1061,9 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594 function updateFromRegistry() public { _onlyOwner(); - moduleRegistry = PolymathRegistry(polymathRegistry).getAddress("ModuleRegistry"); - securityTokenRegistry = PolymathRegistry(polymathRegistry).getAddress("SecurityTokenRegistry"); - polyToken = PolymathRegistry(polymathRegistry).getAddress("PolyToken"); + moduleRegistry = IModuleRegistry(polymathRegistry.getAddress("ModuleRegistry")); + securityTokenRegistry = ISecurityTokenRegistry(polymathRegistry.getAddress("SecurityTokenRegistry")); + polyToken = IERC20(polymathRegistry.getAddress("PolyToken")); } //Ownable Functions diff --git a/contracts/tokens/SecurityTokenProxy.sol b/contracts/tokens/SecurityTokenProxy.sol index 2dff257bf..8a5eb8d09 100644 --- a/contracts/tokens/SecurityTokenProxy.sol +++ b/contracts/tokens/SecurityTokenProxy.sol @@ -33,7 +33,7 @@ contract SecurityTokenProxy is OZStorage, SecurityTokenStorage, OwnedUpgradeabil name = _name; symbol = _symbol; decimals = _decimals; - polymathRegistry = _polymathRegistry; + polymathRegistry = IPolymathRegistry(_polymathRegistry); tokenDetails = _tokenDetails; granularity = _granularity; _owner = msg.sender; diff --git a/contracts/tokens/SecurityTokenStorage.sol b/contracts/tokens/SecurityTokenStorage.sol index f68a972d3..4651d0e25 100644 --- a/contracts/tokens/SecurityTokenStorage.sol +++ b/contracts/tokens/SecurityTokenStorage.sol @@ -1,5 +1,11 @@ pragma solidity 0.5.8; +import "../interfaces/IDataStore.sol"; +import "../interfaces/IModuleRegistry.sol"; +import "../interfaces/IPolymathRegistry.sol"; +import "../interfaces/ISecurityTokenRegistry.sol"; +import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; + contract SecurityTokenStorage { uint8 constant PERMISSION_KEY = 1; @@ -64,13 +70,13 @@ contract SecurityTokenStorage { // set by the issuer/owner of the token address public controller; - address public polymathRegistry; - address public moduleRegistry; - address public securityTokenRegistry; - address public polyToken; + IPolymathRegistry public polymathRegistry; + IModuleRegistry public moduleRegistry; + ISecurityTokenRegistry public securityTokenRegistry; + IERC20 public polyToken; address public getterDelegate; // Address of the data store used to store shared data - address public dataStore; + IDataStore public dataStore; uint256 public granularity;