diff --git a/contracts/modules/TransferManager/ManualApprovalTransferManager.sol b/contracts/modules/TransferManager/ManualApprovalTransferManager.sol index fd888680a..20b1774bc 100644 --- a/contracts/modules/TransferManager/ManualApprovalTransferManager.sol +++ b/contracts/modules/TransferManager/ManualApprovalTransferManager.sol @@ -83,7 +83,7 @@ contract ManualApprovalTransferManager is ITransferManager { * @param _from Address of the sender * @param _to Address of the receiver * @param _amount The amount of tokens to transfer - * @param _isTransfer Whether or not this is an actual transfer or just a test to see if the tokens would be transferrable + * @param _isTransfer Whether or not this is an actual transfer or just a test to see if the tokens would be transferable */ function verifyTransfer(address _from, address _to, uint256 _amount, bytes /* _data */, bool _isTransfer) public returns(Result) { // function must only be called by the associated security token if _isTransfer == true diff --git a/contracts/modules/TransferManager/MaximumVolumeTransferManager.sol b/contracts/modules/TransferManager/MaximumVolumeTransferManager.sol new file mode 100644 index 000000000..cf8b9fe59 --- /dev/null +++ b/contracts/modules/TransferManager/MaximumVolumeTransferManager.sol @@ -0,0 +1,307 @@ +pragma solidity ^0.4.24; + +import "./ITransferManager.sol"; +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; + +/** + * @title Transfer Manager module for capping the amount of token transfers within a period + */ +contract MaximumVolumeTransferManager is ITransferManager { + using SafeMath for uint256; + + bytes32 public constant ADMIN = "ADMIN"; + + enum RollingIntervals { Daily, Weekly, Quarterly, Biannually, Annually } + + struct MaximumVolumeRestriction{ + uint256 maximumVolumeAllowed; + uint256 startTime; + uint256 endTime; + RollingIntervals rollingPeriodInterval; + } + + MaximumVolumeRestriction[] public maximumVolumeRestrictions; + + // mapping from address to RollingIntervals to periodIds to tokens transfered + mapping(address => mapping(uint256 => mapping(uint256 => uint256))) volumeTally; + + // Emit whenever a new maximum volume restriction gets added + event AddNewMaximumVolumeRestriction( + uint256 _index, + uint256 timestamp, + uint256 _maximumVolume, + uint256 _startTime, + uint256 _endTime, + uint256 _rollingPeriodInterval + ); + + // Emit whenever a new maximum volume restriction gets modified + event ModifyMaximumVolumeRestriction( + uint256 _index, + uint256 timestamp, + uint256 _maximumVolume, + uint256 _startTime, + uint256 _endTime, + uint256 _rollingPeriodInterval + ); + + // Emit whenever a new maximum volume restriction gets removed + event RemoveMaximumVolumeRestricion( + address indexed _from, + uint256 timestamp + ); + + /** + * @notice Constructor + * @param _securityToken Address of the security token + * @param _polyAddress Address of the polytoken + */ + constructor (address _securityToken, address _polyAddress) + public + Module(_securityToken, _polyAddress) + { + } + + /** + * @notice This function returns the signature of configure function + */ + function getInitFunction() public pure returns (bytes4) { + return bytes4(0); + } + + /** + * @notice used to verify a transfer transaction and restrict the amount of tokens that can be transfered within a rolling time interval + * @param _from Address of the sender + * @param _amount The amount of tokens to transfer + * @param _isTransfer Whether or not this is an actual transfer or just a test to see if the tokens would be transferable + */ + function verifyTransfer(address _from, address /*_to*/, uint256 _amount, bytes /* _data */, bool _isTransfer) public returns(Result) { + // function must only be called by the associated security token if _isTransfer == true + require(_isTransfer == false || msg.sender == securityToken, "Sender is not owner"); + + // loop over every existing max transfer restriction to check if current transaction falls under their activity interval + if (!paused) { + for(uint256 i = 0; i < maximumVolumeRestrictions.length; i++){ + MaximumVolumeRestriction memory restriction = maximumVolumeRestrictions[i]; + if(now >= restriction.startTime && now <= restriction.endTime){ + uint256 period = _getPeriod(restriction.rollingPeriodInterval); + uint256 periodId = (now.sub(restriction.startTime)).div(period); + + // if the transfer amount causes the total period volume to exceed the maximum value, transfer is invalid + if(_amount.add(volumeTally[_from][uint256(restriction.rollingPeriodInterval)][periodId]) > restriction.maximumVolumeAllowed){ + return Result.INVALID; + }else{ + volumeTally[_from][uint256(restriction.rollingPeriodInterval)][periodId] = _amount.add(volumeTally[_from][uint256(restriction.rollingPeriodInterval)][periodId]); + } + } + } + return Result.VALID; + } + return Result.NA; + } + + /** + * @notice allows admin to add new maximum volume transfer restrictions + * @param _maximumVolume maximum token volume that can be transfered + * @param _startTime timestamp representing when this maximum volume restriction starts + * @param _endTime timestamp representing when this maximum volume restriction ends + * @param _rollingPeriodInterval interval period representing one of five RollingIntervals + */ + function addMaxVolumeRestricion( + uint256 _maximumVolume, + uint256 _startTime, + uint256 _endTime, + uint256 _rollingPeriodInterval) + public withPerm(ADMIN) { + if(_startTime == 0) { + _startTime = now; + } + _checkRestrictionParams(_startTime, _endTime, _rollingPeriodInterval); + + _addMaxVolumeRestricion(_maximumVolume, _startTime, _endTime, _rollingPeriodInterval); + } + + /** + * @notice allows admin to add multiple new maximum volume transfer restrictions + * @param _maximumVolumes maximum token volumes that can be transfered + * @param _startTimes timestamps representing when these maximum volume restrictions start + * @param _endTimes timestamps representing when these maximum volume restrictions end + * @param _rollingPeriodIntervals interval periods representing one of five RollingIntervals + */ + function addMaxVolumeRestricionsMulti( + uint256[] _maximumVolumes, + uint256[] _startTimes, + uint256[] _endTimes, + uint256[] _rollingPeriodIntervals) + public withPerm(ADMIN) { + require(_maximumVolumes.length >= 1, "No restrictions provided"); + require( + _maximumVolumes.length == _startTimes.length && + _maximumVolumes.length == _endTimes.length && + _maximumVolumes.length == _rollingPeriodIntervals.length, + "Input array length mismatch" + ); + + for(uint256 i = 0; i < _maximumVolumes.length; i++){ + _addMaxVolumeRestricion( + _maximumVolumes[i], + _startTimes[i], + _endTimes[i], + _rollingPeriodIntervals[i] + ); + } + } + + /** + * @notice allows admin to modify a maximum volume transfer restriction + * @param _index representing the array index of the maximum volume transfer restriction + * @param _maximumVolume maximum token volume that can be transfered + * @param _startTime timestamp representing when this maximum volume restriction starts + * @param _endTime timestamp representing when this maximum volume restriction ends + * @param _rollingPeriodInterval interval period representing one of five RollingIntervals + */ + function modifyMaximumTransferRestriction( + uint256 _index, + uint256 _maximumVolume, + uint256 _startTime, + uint256 _endTime, + uint256 _rollingPeriodInterval) + public withPerm(ADMIN) { + require(_index < maximumVolumeRestrictions.length, "invalid index"); + require(now < maximumVolumeRestrictions[_index].endTime, "restriction is no longer active"); + + if(_startTime == 0) { + _startTime = now; + } + + _checkRestrictionParams(_startTime, _endTime, _rollingPeriodInterval); + + MaximumVolumeRestriction memory restriction = MaximumVolumeRestriction( + _maximumVolume, + _startTime, + _endTime, + RollingIntervals(_rollingPeriodInterval) + ); + maximumVolumeRestrictions[_index] = restriction; + + emit ModifyMaximumVolumeRestriction( + _index, + now, + _maximumVolume, + _startTime, + _endTime, + _rollingPeriodInterval + ); + } + + /** + * @notice allows admin to delete a maximum volume transfer restriction + * @param _index representing the array index of the maximum volume transfer restriction + */ + function removeMaximumTransferRestriction(uint256 _index) public withPerm(ADMIN){ + require (maximumVolumeRestrictions.length > _index, "invalid index"); + + if(_index < (maximumVolumeRestrictions.length - 1)){ + maximumVolumeRestrictions[_index] = maximumVolumeRestrictions[maximumVolumeRestrictions.length - 1]; + } + + maximumVolumeRestrictions.length = maximumVolumeRestrictions.length - 1; + + emit RemoveMaximumVolumeRestricion( + msg.sender, + now + ); + } + + /** + * @notice Return the permissions flag that are associated with MaximumVolumeTransferManager + */ + function getPermissions() public view returns(bytes32[]) { + bytes32[] memory allPermissions = new bytes32[](1); + allPermissions[0] = ADMIN; + return allPermissions; + } + + /** + * @notice returns a count of all the added maximum volume restrictions + */ + function getMaximumVolumeRestrictionsCount() public view returns(uint) { + return maximumVolumeRestrictions.length; + } + + /** + * @notice internal function to create new maximum volume transfer restrictions + * @param _maximumVolume maximum token volume that can be transfered + * @param _startTime timestamp representing when this maximum volume restriction starts + * @param _endTime timestamp representing when this maximum volume restriction ends + * @param _rollingPeriodInterval interval period representing one of five RollingIntervals + */ + function _addMaxVolumeRestricion( + uint256 _maximumVolume, + uint256 _startTime, + uint256 _endTime, + uint256 _rollingPeriodInterval) + internal { + emit AddNewMaximumVolumeRestriction( + maximumVolumeRestrictions.length, + now, + _maximumVolume, + _startTime, + _endTime, + _rollingPeriodInterval + ); + + maximumVolumeRestrictions.push( + MaximumVolumeRestriction( + _maximumVolume, + _startTime, + _endTime, + RollingIntervals(_rollingPeriodInterval) + ) + ); + } + + + /** + * @notice gets rolling interval period value in seconds + * @param _rollingPeriodInterval one of five RollingIntervals enum value + */ + function _getPeriod(RollingIntervals _rollingPeriodInterval) internal pure returns(uint256){ + uint256 period; + if(_rollingPeriodInterval == RollingIntervals.Daily){ + period = 24 hours; + }else if(_rollingPeriodInterval == RollingIntervals.Weekly){ + period = 7 * 24 hours; + }else if(_rollingPeriodInterval == RollingIntervals.Quarterly){ + period = 3 * 30 * 24 hours; + }else if(_rollingPeriodInterval == RollingIntervals.Biannually){ + period = 6 * 30 * 24 hours; + }else{ + period = 365 * 24 hours; + } + return period; + } + + /** + * @notice internal function for checking restriction parameters + * @param _startTime timestamp representing when this maximum volume restriction starts + * @param _endTime timestamp representing when this maximum volume restriction ends + * @param _rollingPeriodInterval interval period representing one of five RollingIntervals + */ + function _checkRestrictionParams( + uint256 _startTime, + uint256 _endTime, + uint256 _rollingPeriodInterval + ) internal view { + require( + uint256(RollingIntervals.Annually) >= _rollingPeriodInterval, + "invalid rolling period interval - should be < 5" + ); + require(_endTime > _startTime && _endTime > now, 'invalid endTime'); + require( + _getPeriod(RollingIntervals(_rollingPeriodInterval)) <= _endTime.sub(_startTime), + "rolling interval must be less than or equal to the difference between endTime and startTime" + ); + } + +} diff --git a/contracts/modules/TransferManager/MaximumVolumeTransferManagerFactory.sol b/contracts/modules/TransferManager/MaximumVolumeTransferManagerFactory.sol new file mode 100644 index 000000000..19c6aaeb6 --- /dev/null +++ b/contracts/modules/TransferManager/MaximumVolumeTransferManagerFactory.sol @@ -0,0 +1,98 @@ +pragma solidity ^0.4.24; + +import "./MaximumVolumeTransferManager.sol"; +import "../ModuleFactory.sol"; + +contract MaximumVolumeTransferManagerFactory is ModuleFactory{ + + /** + * @notice Constructor + * @param _polyAddress Address of the polytoken + * @param _setupCost Setup cost of the module + * @param _usageCost Usage cost of the module + * @param _subscriptionCost Subscription cost of the module + */ + constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public + ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost) + { + version = "1.0.0"; + name = "MaximumVolumeTransferManager"; + title = "Maximum Volume Transfer Manager"; + description = "limit the volume of transferable tokens within a rolling time interval"; + compatibleSTVersionRange["lowerBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0)); + compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0)); + } + + /** + * @notice used to launch the Module with the help of factory + * @return address Contract address of the Module + */ + function deploy(bytes /* _data */) external returns(address) { + if (setupCost > 0) + require(polyToken.transferFrom(msg.sender, owner, setupCost), "Failed transferFrom because of sufficent Allowance is not provided"); + address maximumVolumeTransferManager = new MaximumVolumeTransferManager(msg.sender, address(polyToken)); + emit GenerateModuleFromFactory(address(maximumVolumeTransferManager), getName(), address(this), msg.sender, setupCost, now); + return address(maximumVolumeTransferManager); + } + + /** + * @notice Type of the Module factory + */ + function getTypes() external view returns(uint8[]) { + uint8[] memory res = new uint8[](1); + res[0] = 2; + return res; + } + + /** + * @notice Get the name of the Module + */ + function getName() public view returns(bytes32) { + return name; + } + + /** + * @notice Get the description of the Module + */ + function getDescription() external view returns(string) { + return description; + } + + /** + * @notice Get the title of the Module + */ + function getTitle() external view returns(string) { + return title; + } + + /** + * @notice Get the version of the Module + */ + function getVersion() external view returns(string) { + return version; + } + + /** + * @notice Get the setup cost of the module + */ + function getSetupCost() external view returns (uint256) { + return setupCost; + } + + /** + * @notice Returns the instructions associated with the module + */ + function getInstructions() external view returns(string) { + return "Allows an issuer to restrict the total volume of tokens that can be transfered within a rolling time interval."; + } + + /** + * @notice Get the tags related to the module factory + */ + function getTags() external view returns(bytes32[]) { + bytes32[] memory availableTags = new bytes32[](2); + availableTags[0] = "MaximumVolume"; + availableTags[1] = "Transfer Restriction"; + return availableTags; + } +} diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 0994e249e..002ba91b4 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -4,6 +4,7 @@ const GeneralPermissionManagerFactory = artifacts.require('./GeneralPermissionMa const PercentageTransferManagerFactory = artifacts.require('./PercentageTransferManagerFactory.sol') const USDTieredSTOProxyFactory = artifacts.require('./USDTieredSTOProxyFactory.sol'); const CountTransferManagerFactory = artifacts.require('./CountTransferManagerFactory.sol') +const MaximumVolumeTransferManagerFactory = artifacts.require('./MaximumVolumeTransferManagerFactory.sol') const EtherDividendCheckpointFactory = artifacts.require('./EtherDividendCheckpointFactory.sol') const ERC20DividendCheckpointFactory = artifacts.require('./ERC20DividendCheckpointFactory.sol') const ModuleRegistry = artifacts.require('./ModuleRegistry.sol'); @@ -161,6 +162,10 @@ module.exports = function (deployer, network, accounts) { // D) Deploy the PercentageTransferManagerFactory Contract (Factory used to generate the PercentageTransferManager contract use // to track the percentage of investment the investors could do for a particular security token) return deployer.deploy(PercentageTransferManagerFactory, PolyToken, 0, 0, 0, {from: PolymathAccount}); + }).then(() => { + // D) Deploy the MaximumVolumeTransferManagerFactory Contract (Factory used to generate the MaximumVolumeTransferManager contract use + // to restrict the maximum volume of tokens which can be transfered within a rolling time interval) + return deployer.deploy(MaximumVolumeTransferManagerFactory, PolyToken, 0, 0, 0, {from: PolymathAccount}); }).then(() => { // D) Deploy the EtherDividendCheckpointFactory Contract (Factory used to generate the EtherDividendCheckpoint contract use // to provide the functionality of the dividend in terms of ETH) @@ -200,6 +205,10 @@ module.exports = function (deployer, network, accounts) { // D) Register the PercentageTransferManagerFactory in the ModuleRegistry to make the factory available at the protocol level. // So any securityToken can use that factory to generate the PercentageTransferManager contract. return moduleRegistry.registerModule(PercentageTransferManagerFactory.address, {from: PolymathAccount}); + }).then(() => { + // D) Register the MaximumVolumeTransferManagerFactory in the ModuleRegistry to make the factory available at the protocol level. + // So any securityToken can use that factory to generate the MaximumVolumeTransferManager contract. + return moduleRegistry.registerModule(MaximumVolumeTransferManagerFactory.address, {from: PolymathAccount}); }).then(() => { // D) Register the CountTransferManagerFactory in the ModuleRegistry to make the factory available at the protocol level. // So any securityToken can use that factory to generate the CountTransferManager contract. @@ -259,6 +268,11 @@ module.exports = function (deployer, network, accounts) { // contract, Factory should comes under the verified list of factories or those factories deployed by the securityToken issuers only. // Here it gets verified because it is deployed by the third party account (Polymath Account) not with the issuer accounts. return moduleRegistry.verifyModule(ManualApprovalTransferManagerFactory.address, true, {from: PolymathAccount}); + }).then(() => { + // G) Once the MaximumVolumeTransferManagerFactory registered with the ModuleRegistry contract then for making them accessble to the securityToken + // contract, Factory should comes under the verified list of factories or those factories deployed by the securityToken issuers only. + // Here it gets verified because it is deployed by the third party account (Polymath Account) not with the issuer accounts. + return moduleRegistry.verifyModule(MaximumVolumeTransferManagerFactory.address, true, {from: PolymathAccount}); }).then(() => { // M) Deploy the CappedSTOFactory (Use to generate the CappedSTO contract which will used to collect the funds ). return deployer.deploy(CappedSTOFactory, PolyToken, cappedSTOSetupCost, 0, 0, {from: PolymathAccount}) @@ -313,6 +327,7 @@ module.exports = function (deployer, network, accounts) { CountTransferManagerFactory: ${CountTransferManagerFactory.address} PercentageTransferManagerFactory: ${PercentageTransferManagerFactory.address} ManualApprovalTransferManagerFactory: ${ManualApprovalTransferManagerFactory.address} + MaximumVolumeTransferManagerFactory: ${MaximumVolumeTransferManagerFactory.address} EtherDividendCheckpointFactory: ${EtherDividendCheckpointFactory.address} ERC20DividendCheckpointFactory: ${ERC20DividendCheckpointFactory.address} --------------------------------------------------------------------------------- diff --git a/test/helpers/createInstances.js b/test/helpers/createInstances.js index 2021d350e..496ecde37 100644 --- a/test/helpers/createInstances.js +++ b/test/helpers/createInstances.js @@ -11,6 +11,7 @@ const SecurityTokenRegistryMock = artifacts.require("./SecurityTokenRegistryMock const ERC20DividendCheckpointFactory = artifacts.require("./ERC20DividendCheckpointFactory.sol"); const EtherDividendCheckpointFactory = artifacts.require("./EtherDividendCheckpointFactory.sol"); const ManualApprovalTransferManagerFactory = artifacts.require("./ManualApprovalTransferManagerFactory.sol"); +const MaximumVolumeTransferManagerFactory = artifacts.require("./MaximumVolumeTransferManagerFactory.sol"); const SingleTradeVolumeRestrictionManagerFactory = artifacts.require('./SingleTradeVolumeRestrictionTMFactory.sol'); const TrackedRedemptionFactory = artifacts.require("./TrackedRedemptionFactory.sol"); const PercentageTransferManagerFactory = artifacts.require("./PercentageTransferManagerFactory.sol"); @@ -43,6 +44,7 @@ let I_MockBurnFactory; let I_MockWrongTypeBurnFactory; let I_SingleTradeVolumeRestrictionManagerFactory; let I_ManualApprovalTransferManagerFactory; +let I_MaximumVolumeTransferManagerFactory; let I_VolumeRestrictionTransferManagerFactory; let I_PercentageTransferManagerFactory; let I_EtherDividendCheckpointFactory; @@ -231,6 +233,18 @@ export async function deployManualApprovalTMAndVerifyed(accountPolymath, MRProxy return new Array(I_ManualApprovalTransferManagerFactory); } +export async function deployMaximumVolumeTMAndVerifyed(accountPolymath, MRProxyInstance, polyToken, setupCost) { + I_MaximumVolumeTransferManagerFactory = await MaximumVolumeTransferManagerFactory.new(polyToken, setupCost, 0, 0, { from: accountPolymath }); + assert.notEqual( + I_MaximumVolumeTransferManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "MaximumVolumeTransferManagerFactory contract was not deployed" + ); + + await registerAndVerifyByMR(I_MaximumVolumeTransferManagerFactory.address, accountPolymath, MRProxyInstance); + return new Array(I_MaximumVolumeTransferManagerFactory); +} + export async function deployPercentageTMAndVerified(accountPolymath, MRProxyInstance, polyToken, setupCost) { I_PercentageTransferManagerFactory = await PercentageTransferManagerFactory.new(polyToken, setupCost, 0, 0, { from: accountPolymath }); assert.notEqual( diff --git a/test/z_maximum_volume_transfer_manager.js b/test/z_maximum_volume_transfer_manager.js new file mode 100644 index 000000000..deb420d76 --- /dev/null +++ b/test/z_maximum_volume_transfer_manager.js @@ -0,0 +1,845 @@ +import latestTime from "./helpers/latestTime"; +import { duration, ensureException, promisifyLogWatch, latestBlock } from "./helpers/utils"; +import takeSnapshot, { increaseTime, revertToSnapshot } from "./helpers/time"; +import { encodeProxyCall } from "./helpers/encodeCall"; +import { catchRevert } from "./helpers/exceptions"; +import { setUpPolymathNetwork, deployMaximumVolumeTMAndVerifyed, deployGPMAndVerifyed, deployCountTMAndVerifyed } from "./helpers/createInstances"; + +const SecurityToken = artifacts.require("./SecurityToken.sol"); +const GeneralTransferManager = artifacts.require("./GeneralTransferManager"); +const MaximumVolumeTransferManager = artifacts.require("./MaximumVolumeTransferManager"); +const CountTransferManager = artifacts.require("./CountTransferManager"); +const GeneralPermissionManager = artifacts.require("./GeneralPermissionManager"); + +const Web3 = require("web3"); +const BigNumber = require("bignumber.js"); +const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); // Hardcoded development port + +contract("MaximumVolumeTransferManager", accounts => { + // Accounts Variable declaration + let account_polymath; + let account_issuer; + let token_owner; + let account_investor1; + let account_investor2; + let account_investor3; + let account_investor4; + let account_investor5; + + // investor Details + let fromTime = latestTime(); + let toTime = latestTime(); + let expiryTime = toTime + duration.days(15); + + let message = "Transaction Should Fail!"; + + // Contract Instance Declaration + let I_GeneralPermissionManagerFactory; + let I_GeneralTransferManagerFactory; + let I_SecurityTokenRegistryProxy; + let I_MaximumVolumeTransferManagerFactory; + let P_MaximumVolumeTransferManagerFactory; + let P_MaximumVolumeTransferManager; + let I_CountTransferManagerFactory; + let I_GeneralPermissionManager; + let I_MaximumVolumeTransferManager; + let I_CountTransferManager; + let I_GeneralTransferManager; + let I_ModuleRegistryProxy; + let I_ModuleRegistry; + let I_FeatureRegistry; + let I_SecurityTokenRegistry; + let I_MRProxied; + let I_STRProxied; + let I_STFactory; + let I_SecurityToken; + let I_PolyToken; + let I_PolymathRegistry; + + // SecurityToken Details + const name = "Team"; + const symbol = "sap"; + const tokenDetails = "This is equity type of issuance"; + const decimals = 18; + const contact = "team@polymath.network"; + + // Module key + const delegateManagerKey = 1; + const transferManagerKey = 2; + const stoKey = 3; + + // Initial fee for ticker registry and security token registry + const initRegFee = web3.utils.toWei("250"); + + const STOParameters = ["uint256", "uint256", "uint256", "uint256", "uint8[]", "address"]; + + before(async () => { + // Accounts setup + account_polymath = accounts[0]; + account_issuer = accounts[1]; + + token_owner = account_issuer; + + account_investor1 = accounts[6]; + account_investor2 = accounts[7]; + account_investor3 = accounts[8]; + account_investor4 = accounts[9]; + account_investor5 = accounts[5]; + + // Step 1: Deploy the genral PM ecosystem + let instances = await setUpPolymathNetwork(account_polymath, token_owner); + + [ + I_PolymathRegistry, + I_PolyToken, + I_FeatureRegistry, + I_ModuleRegistry, + I_ModuleRegistryProxy, + I_MRProxied, + I_GeneralTransferManagerFactory, + I_STFactory, + I_SecurityTokenRegistry, + I_SecurityTokenRegistryProxy, + I_STRProxied + ] = instances; + + // STEP 2: Deploy the GeneralDelegateManagerFactory + [I_GeneralPermissionManagerFactory] = await deployGPMAndVerifyed(account_polymath, I_MRProxied, I_PolyToken.address, 0); + // STEP 3: Deploy the MaximumVolumeTransferManagerFactory + [I_MaximumVolumeTransferManagerFactory] = await deployMaximumVolumeTMAndVerifyed(account_polymath, I_MRProxied, I_PolyToken.address, 0); + // STEP 4: Deploy the Paid MaximumVolumeTransferManagerFactory + [P_MaximumVolumeTransferManagerFactory] = await deployMaximumVolumeTMAndVerifyed(account_polymath, I_MRProxied, I_PolyToken.address, web3.utils.toWei("500", "ether")); + // STEP 5: Deploy the CountTransferManagerFactory + [I_CountTransferManagerFactory] = await deployCountTMAndVerifyed(account_polymath, I_MRProxied, I_PolyToken.address, 0); + + // Printing all the contract addresses + console.log(` + --------------------- Polymath Network Smart Contracts: --------------------- + PolymathRegistry: ${I_PolymathRegistry.address} + SecurityTokenRegistryProxy: ${I_SecurityTokenRegistryProxy.address} + SecurityTokenRegistry: ${I_SecurityTokenRegistry.address} + ModuleRegistry: ${I_ModuleRegistry.address} + FeatureRegistry: ${I_FeatureRegistry.address} + + STFactory: ${I_STFactory.address} + GeneralTransferManagerFactory: ${I_GeneralTransferManagerFactory.address} + GeneralPermissionManagerFactory: ${I_GeneralPermissionManagerFactory.address} + + MaximumVolumeTransferManagerFactory: ${I_MaximumVolumeTransferManagerFactory.address} + CountTransferManagerFactory: ${I_CountTransferManagerFactory.address} + ----------------------------------------------------------------------------- + `); + }); + + describe("Generate the SecurityToken", async () => { + it("Should register the ticker before the generation of the security token", async () => { + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let tx = await I_STRProxied.registerTicker(token_owner, symbol, contact, { from: token_owner }); + assert.equal(tx.logs[0].args._owner, token_owner); + assert.equal(tx.logs[0].args._ticker, symbol.toUpperCase()); + }); + + it("Should generate the new security token with the same symbol as registered above", async () => { + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let _blockNo = latestBlock(); + let tx = await I_STRProxied.generateSecurityToken(name, symbol, tokenDetails, false, { from: token_owner }); + + // Verify the successful generation of the security token + assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed"); + + I_SecurityToken = SecurityToken.at(tx.logs[1].args._securityTokenAddress); + + const log = await promisifyLogWatch(I_SecurityToken.ModuleAdded({ from: _blockNo }), 1); + + // Verify that GeneralTransferManager module get added successfully or not + assert.equal(log.args._types[0].toNumber(), 2); + assert.equal(web3.utils.toUtf8(log.args._name), "GeneralTransferManager"); + }); + + it("Should intialize the auto attached modules", async () => { + let moduleData = (await I_SecurityToken.getModulesByType(2))[0]; + I_GeneralTransferManager = GeneralTransferManager.at(moduleData); + }); + }); + + describe("Buy tokens using whitelist & manual approvals", async () => { + it("Should Buy the tokens", async () => { + // Add the Investor in to the whitelist + + let tx = await I_GeneralTransferManager.modifyWhitelist( + account_investor1, + latestTime(), + latestTime(), + latestTime() + duration.days(10), + true, + { + from: account_issuer, + gas: 6000000 + } + ); + + assert.equal( + tx.logs[0].args._investor.toLowerCase(), + account_investor1.toLowerCase(), + "Failed in adding the investor in whitelist" + ); + + // Jump time + await increaseTime(5000); + + // Mint some tokens + await I_SecurityToken.mint(account_investor1, web3.utils.toWei("4", "ether"), { from: token_owner }); + + assert.equal((await I_SecurityToken.balanceOf(account_investor1)).toNumber(), web3.utils.toWei("4", "ether")); + }); + + it("Should Buy some more tokens", async () => { + // Add the Investor in to the whitelist + + let tx = await I_GeneralTransferManager.modifyWhitelist( + account_investor2, + latestTime(), + latestTime(), + latestTime() + duration.days(10), + true, + { + from: account_issuer, + gas: 6000000 + } + ); + + assert.equal( + tx.logs[0].args._investor.toLowerCase(), + account_investor2.toLowerCase(), + "Failed in adding the investor in whitelist" + ); + + // Mint some tokens + await I_SecurityToken.mint(account_investor2, web3.utils.toWei("1", "ether"), { from: token_owner }); + + assert.equal((await I_SecurityToken.balanceOf(account_investor2)).toNumber(), web3.utils.toWei("1", "ether")); + }); + + it("Should successfully attach the MaximumVolumeTransferManager with the security token", async () => { + await I_PolyToken.getTokens(web3.utils.toWei("500", "ether"), token_owner); + await catchRevert( + I_SecurityToken.addModule(P_MaximumVolumeTransferManagerFactory.address, "0x", web3.utils.toWei("500", "ether"), 0, { + from: token_owner + }) + ); + }); + + it("Should successfully attach the General permission manager factory with the security token", async () => { + let snapId = await takeSnapshot(); + await I_PolyToken.transfer(I_SecurityToken.address, web3.utils.toWei("500", "ether"), { from: token_owner }); + const tx = await I_SecurityToken.addModule( + P_MaximumVolumeTransferManagerFactory.address, + "0x", + web3.utils.toWei("500", "ether"), + 0, + { from: token_owner } + ); + assert.equal(tx.logs[3].args._types[0].toNumber(), transferManagerKey, "Maximum Volume Transfer Manager doesn't get deployed"); + assert.equal( + web3.utils.toAscii(tx.logs[3].args._name).replace(/\u0000/g, ""), + "MaximumVolumeTransferManager", + "MaximumVolumeTransferManagerFactory module was not added" + ); + P_MaximumVolumeTransferManagerFactory = MaximumVolumeTransferManager.at(tx.logs[3].args._module); + await revertToSnapshot(snapId); + }); + + it("Should successfully attach the MaximumVolumeTransferManager with the security token", async () => { + const tx = await I_SecurityToken.addModule(I_MaximumVolumeTransferManagerFactory.address, "", 0, 0, { from: token_owner }); + assert.equal(tx.logs[2].args._types[0].toNumber(), transferManagerKey, "MaximumVolumeTransferManager doesn't get deployed"); + assert.equal( + web3.utils.toUtf8(tx.logs[2].args._name), + "MaximumVolumeTransferManager", + "MaximumVolumeTransferManager module was not added" + ); + I_MaximumVolumeTransferManager = MaximumVolumeTransferManager.at(tx.logs[2].args._module); + }); + + it("Cannot call verifyTransfer on the TM directly if _isTransfer == true", async () => { + await catchRevert( + I_MaximumVolumeTransferManager.verifyTransfer( + account_investor4, + account_investor4, + web3.utils.toWei("2", "ether"), + "", + true, + { from: token_owner } + ) + ); + }); + + it("Can call verifyTransfer on the TM directly if _isTransfer == false", async () => { + await I_MaximumVolumeTransferManager.verifyTransfer( + account_investor4, + account_investor4, + web3.utils.toWei("2", "ether"), + "", + false, + { from: token_owner } + ); + }); + + it("Add a new token holder", async () => { + let tx = await I_GeneralTransferManager.modifyWhitelist( + account_investor3, + latestTime(), + latestTime(), + latestTime() + duration.days(10), + true, + { + from: account_issuer, + gas: 6000000 + } + ); + + assert.equal( + tx.logs[0].args._investor.toLowerCase(), + account_investor3.toLowerCase(), + "Failed in adding the investor in whitelist" + ); + + // Add the Investor in to the whitelist + // Mint some tokens + await I_SecurityToken.mint(account_investor3, web3.utils.toWei("1", "ether"), { from: token_owner }); + + assert.equal((await I_SecurityToken.balanceOf(account_investor3)).toNumber(), web3.utils.toWei("1", "ether")); + }); + + it("Should pause the tranfers at transferManager level", async() => { + let tx = await I_MaximumVolumeTransferManager.pause({from: token_owner}); + }); + + it("Should still be able to transfer between existing token holders", async () => { + // Add the Investor in to the whitelist + // Mint some tokens + await I_SecurityToken.transfer(account_investor1, web3.utils.toWei("1", "ether"), { from: account_investor2 }); + + assert.equal((await I_SecurityToken.balanceOf(account_investor1)).toNumber(), web3.utils.toWei("5", "ether")); + }); + + it("Should unpause the tranfers at transferManager level", async() => { + await I_MaximumVolumeTransferManager.unpause({from: token_owner}); + }); + + let max_vol = web3.utils.toWei('1', 'ether'); + let startTime = 0; //now + let endTime = latestTime() + duration.years(2); + let rollingInterval = 1; //weekly + + it("should fail to add a new max volume restriction when called by a non-admin account", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + startTime, + endTime, + rollingInterval, + { from: account_investor1 } + ); + } catch(error) { + console.log(` tx revert -> not an admin`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should not allow creation of a maximum volume restriction if endTime is set to 0", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + startTime, + 0, + rollingInterval, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> invalid end time`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should not allow creation of a maximum volume restriction if rolling interval is not recognized", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + startTime, + endTime, + 6, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> invalid rolling interval enum`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should not allow creation of a maximum volume restriction if startTime is equal to endTime", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + endTime, + endTime, + rollingInterval, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> invalid startTime and endTime`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should not allow creation of a maximum volume restriction if endTime is less than startTime", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + endTime, + startTime, + rollingInterval, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> invalid startTime and endTime`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should not allow creation of a maximum volume restriction if endTime is less than current time", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + latestTime() - 100000, + latestTime() - 100, + rollingInterval, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> endTime is in the past`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should not allow creation of a maximum volume restriction if rolling interval is greater than the restriction period", async() => { + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + startTime, + latestTime() + 10, + 0, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> rolling interval is bigger than the restriction period`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should create a Maximum Volume Transfer Restriction", async()=>{ + await I_SecurityToken.changeGranularity(Math.pow(10, 5), { from: token_owner }); + const tx = await I_MaximumVolumeTransferManager.addMaxVolumeRestricion( + max_vol, + startTime, + endTime, + rollingInterval, + { from: token_owner } + ); + const logs = tx.logs[0]; + const currentStartTime = (await web3.eth.getBlock('latest')).timestamp; + + assert.equal( + 1, + await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(), + "Restriction not added to the array" + ); + assert.equal("AddNewMaximumVolumeRestriction", logs['event'], "Invalid event"); + assert.equal(currentStartTime, logs['args']['_startTime'], "Invalid start time"); + assert.equal(endTime, logs['args']['_endTime'], "Invalid end time"); + assert.equal(rollingInterval , logs['args']['_rollingPeriodInterval'], "Invalid rolling interval"); + }); + + it("Should not be able to transfer between existing token holders over maximum limit", async() => { + let errorThrown = false; + try { + await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('1.1', 'ether'), { from: account_investor1 }); + } catch(error) { + console.log(` tx revert -> Transfer value exceeds maximum limit`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should allow all token transfers upto the limit and then reject further transfers until the next period starts", async () => { + const initialBalance = await I_SecurityToken.balanceOf(account_investor3); + assert.equal(initialBalance.toNumber(), web3.utils.toWei('1', 'ether')); + + await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('0.4', 'ether'), { from: account_investor1 }); + await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('0.2', 'ether'), { from: account_investor1 }); + await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('0.4', 'ether'), { from: account_investor1 }); + + let finalBalance = await I_SecurityToken.balanceOf(account_investor3); + assert.equal(finalBalance.toNumber(), web3.utils.toWei('2', 'ether')); + + let errorThrown = false; + try { + await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('1', 'ether'), { from: account_investor1 }); + } catch(error) { + console.log(` tx revert -> maximum transfer limit exceeded`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + + // increase evm time by one week/604800 seconds + await increaseTime(604800); + + await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('1', 'ether'), { from: account_investor1 }); + + finalBalance = await I_SecurityToken.balanceOf(account_investor3); + assert.equal(finalBalance.toNumber(), web3.utils.toWei('3', 'ether')); + }); + + it("should allow for modification of an existing maximum volume transfer restriction with new startTime set to zero", async()=>{ + const nRestrictions = await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(); + const index = nRestrictions - 1; + + const newMaxVolume = web3.utils.toWei('0.5', 'ether'); + const newStartTime = 0; + const newEndTime = latestTime() + duration.years(3); + const newRollingInterval = 4; + + const tx = await I_MaximumVolumeTransferManager.modifyMaximumTransferRestriction( + index, + newMaxVolume, + newStartTime, + newEndTime, + newRollingInterval, + { from: token_owner } + ); + + const logs = tx.logs[0]; + const currentStartTime = (await web3.eth.getBlock('latest')).timestamp; + + assert.equal("ModifyMaximumVolumeRestriction", logs['event'], "Invalid event"); + assert.equal(currentStartTime, logs['args']['_startTime'], "Invalid start time"); + assert.equal(newEndTime, logs['args']['_endTime'], "Invalid end time"); + assert.equal(newRollingInterval , logs['args']['_rollingPeriodInterval'], "Invalid rolling interval"); + }); + + it("should allow for modification of an existing maximum volume transfer restriction", async()=>{ + const nRestrictions = await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(); + const index = nRestrictions - 1; + + const newMaxVolume = web3.utils.toWei('0.5', 'ether'); + const newStartTime = latestTime() - duration.years(1); + const newEndTime = latestTime() + duration.years(1); + const newRollingInterval = 3; + + const tx = await I_MaximumVolumeTransferManager.modifyMaximumTransferRestriction( + index, + newMaxVolume, + newStartTime, + newEndTime, + newRollingInterval, + { from: token_owner } + ); + const logs = tx.logs[0]; + const currentStartTime = (await web3.eth.getBlock('latest')).timestamp; + + assert.equal("ModifyMaximumVolumeRestriction", logs['event'], "Invalid event"); + assert.equal(newStartTime, logs['args']['_startTime'], "Invalid start time"); + assert.equal(newEndTime, logs['args']['_endTime'], "Invalid end time"); + assert.equal(newRollingInterval , logs['args']['_rollingPeriodInterval'], "Invalid rolling interval"); + }); + + it("should not allow for modification of an expired restriction", async()=>{ + // increase evm time by 3 years + await increaseTime(94608000); + + let errorThrown = false; + try { + await I_MaximumVolumeTransferManager.modifyMaximumTransferRestriction( + 0, + web3.utils.toWei('5', 'ether'), + 0, + latestTime() + duration.years(1), + 3, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> Transfer restriction has already expired`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should fail to modify any restriction if index provided is wrong", async() =>{ + let errorThrown = false; + const nRestrictions = await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(); + try { + await I_MaximumVolumeTransferManager.modifyMaximumTransferRestriction( + nRestrictions, + web3.utils.toWei('5', 'ether'), + 0, + latestTime() + duration.years(1), + 1, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> Index out of bounds`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should fail to add to add multiple new max volume restrictions when called by a non-admin account", async() => { + const maxVolumes = [100000000, 500000000, 6000000000]; + const startTimes = [0, 0, 0]; + const endTimes = [latestTime() + duration.years(1), latestTime() + duration.years(2), latestTime() + duration.years(3)]; + const rollingIntervals = [0, 2, 4]; + + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricionsMulti( + maxVolumes, + startTimes, + endTimes, + rollingIntervals, + { from: account_investor1 } + ); + } catch(error) { + console.log(` tx revert -> not an admin`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should fail to add to add multiple new max volume restrictions when max volumes array is empty", async() => { + const maxVolumes = []; + const startTimes = [0, 0, 0]; + const endTimes = [latestTime() + duration.years(1), latestTime() + duration.years(2), latestTime() + duration.years(3)]; + const rollingIntervals = [0, 2, 4]; + + let errorThrown = false; + try{ + await I_MaximumVolumeTransferManager.addMaxVolumeRestricionsMulti( + maxVolumes, + startTimes, + endTimes, + rollingIntervals, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> max volumes array is empty`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should fail if input array lengths mismatch for mutiple maximum volume transfer restrictions", async()=>{ + const maxVolumes = [100000000, 6000000000]; + const startTimes = [0, 0, 0]; + const endTimes = [latestTime() + duration.years(1)]; + const rollingIntervals = [0, 2, 4]; + + let errorThrown = false; + try { + await I_MaximumVolumeTransferManager.addMaxVolumeRestricionsMulti( + maxVolumes, + startTimes, + endTimes, + rollingIntervals, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> Array lengths mis-match`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should allow for addition of multiple maximum volume restrictions", async()=>{ + const maxVolumes = [100000, 200000, 300000, 400000, 500000]; + const startTimes = [0, 0, 0, latestTime() - 10000, latestTime() + 10000]; + const endTimes = [latestTime() + duration.weeks(1), latestTime() + duration.weeks(2), latestTime() + duration.years(1), latestTime() + duration.years(2), latestTime() + duration.years(3)]; + const rollingIntervals = [0, 1, 2, 3 ,4]; + + await I_MaximumVolumeTransferManager.addMaxVolumeRestricionsMulti( + maxVolumes, + startTimes, + endTimes, + rollingIntervals, + { from: token_owner } + ); + + assert.equal( + 6, + await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(), + "Failed to add multiple restrictions" + ); + }); + + it("should restrict transfers to their set maximum limits", async()=>{ + await I_SecurityToken.transfer(account_investor4, 100000, { from: account_investor1 }); + await catchRevert( + I_SecurityToken.transfer(account_investor4, 1, { from: account_investor1 }) + ); + + await increaseTime(duration.days(1)); + await I_SecurityToken.transfer(account_investor4, 100000, { from: account_investor1 }); + await catchRevert( + I_SecurityToken.transfer(account_investor4, 1, { from: account_investor1 }) + ); + + await increaseTime(duration.days(1)); + await catchRevert( + I_SecurityToken.transfer(account_investor4, 1, { from: account_investor1 }) + ); + + await increaseTime(duration.weeks(1)); + await I_SecurityToken.transfer(account_investor4, 100000, { from: account_investor1 }); + await catchRevert( + I_SecurityToken.transfer(account_investor4, 1, { from: account_investor1 }) + ); + + await increaseTime(duration.weeks(1)); + await catchRevert( + I_SecurityToken.transfer(account_investor4, 1, { from: account_investor1 }) + ); + }); + + it("should fail to delete any restriction if index provided is wrong", async() =>{ + let errorThrown = false; + const nRestrictions = await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(); + try { + await I_MaximumVolumeTransferManager.removeMaximumTransferRestriction( + nRestrictions, + { from: token_owner } + ); + } catch(error) { + console.log(` tx revert -> Index out of bounds`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should fail to delete any restriction if called by a non-admin account", async() =>{ + let errorThrown = false; + const nRestrictions = await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(); + try { + await I_MaximumVolumeTransferManager.removeMaximumTransferRestriction( + nRestrictions, + { from: account_investor1 } + ); + } catch(error) { + console.log(` tx revert -> account not an admin`.grey); + ensureException(error); + errorThrown = true; + } + assert.ok(errorThrown, message); + }); + + it("should allow for successful deletion of maximum volume transfer restrictions", async () => { + let tx; + let logs; + const nRestrictions = await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(); + for (let i = 0; i < nRestrictions; i++) { + tx = await I_MaximumVolumeTransferManager.removeMaximumTransferRestriction(0, { from: token_owner }); + logs = tx.logs[0]; + assert.equal("RemoveMaximumVolumeRestricion", logs['event'], "Invalid event"); + } + assert.equal( + 0, + await I_MaximumVolumeTransferManager.getMaximumVolumeRestrictionsCount.call(), + "Failed to remove all max volume restrictions" + ); + }); + + it("Should successfully attach the CountTransferManager with the security token (count of 1)", async () => { + let bytesCountTM = web3.eth.abi.encodeFunctionCall( + { + name: "configure", + type: "function", + inputs: [ + { + type: "uint256", + name: "_maxHolderCount" + } + ] + }, + [1] + ); + + const tx = await I_SecurityToken.addModule(I_CountTransferManagerFactory.address, bytesCountTM, 0, 0, { from: token_owner }); + assert.equal(tx.logs[2].args._types[0].toNumber(), transferManagerKey, "CountTransferManager doesn't get deployed"); + let name = web3.utils.toUtf8(tx.logs[2].args._name); + assert.equal(name, "CountTransferManager", "CountTransferManager module was not added"); + I_CountTransferManager = CountTransferManager.at(tx.logs[2].args._module); + }); + + it("Should get the permission list", async () => { + let perm = await I_MaximumVolumeTransferManager.getPermissions.call(); + assert.equal(perm.length, 1); + }); + + it("Should get the init function", async () => { + let byte = await I_MaximumVolumeTransferManager.getInitFunction.call(); + assert.equal(web3.utils.toAscii(byte).replace(/\u0000/g, ""), 0); + }); + }); + + describe("MaximumVolume Transfer Manager Factory test cases", async () => { + it("Should get the exact details of the factory", async () => { + assert.equal(await I_MaximumVolumeTransferManagerFactory.setupCost.call(), 0); + assert.equal((await I_MaximumVolumeTransferManagerFactory.getTypes.call())[0], 2); + let name = web3.utils.toUtf8(await I_MaximumVolumeTransferManagerFactory.getName.call()); + assert.equal(name, "MaximumVolumeTransferManager", "Wrong Module added"); + let desc = await I_MaximumVolumeTransferManagerFactory.getDescription.call(); + assert.equal(desc, "limit the volume of transferable tokens within a rolling time interval", "Wrong Module added"); + let title = await I_MaximumVolumeTransferManagerFactory.getTitle.call(); + assert.equal(title, "Maximum Volume Transfer Manager", "Wrong Module added"); + let inst = await I_MaximumVolumeTransferManagerFactory.getInstructions.call(); + assert.equal( + inst, + "Allows an issuer to restrict the total volume of tokens that can be transfered within a rolling time interval.", + "Wrong Module added" + ); + assert(await I_MaximumVolumeTransferManagerFactory.getVersion.call(), '1.0.0'); + }); + + it("Should get the tags of the factory", async () => { + let tags = await I_MaximumVolumeTransferManagerFactory.getTags.call(); + assert.equal(web3.utils.toUtf8(tags[0]), "MaximumVolume"); + }); + }); +}); +