@@ -52,6 +52,7 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
5252 uint256 _timestamp
5353 );
5454
55+ event LogGranularityChanged (uint256 _oldGranularity , uint256 _newGranularity );
5556 event LogModuleRemoved (uint8 indexed _type , address _module , uint256 _timestamp );
5657 event LogModuleBudgetChanged (uint8 indexed _moduleType , address _module , uint256 _budget );
5758 event Mint (address indexed to , uint256 amount );
@@ -71,10 +72,16 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
7172 _;
7273 }
7374
75+ modifier checkGranularity (uint256 _amount ) {
76+ require (_amount.div (granularity).mul (granularity) == _amount, "Unable to modify token balances at this granularity " );
77+ _;
78+ }
79+
7480 constructor (
7581 string _name ,
7682 string _symbol ,
7783 uint8 _decimals ,
84+ uint256 _granularity ,
7885 bytes32 _tokenDetails ,
7986 address _securityTokenRegistry
8087 )
@@ -85,6 +92,7 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
8592 moduleRegistry = ISecurityTokenRegistry (_securityTokenRegistry).moduleRegistry ();
8693 polyToken = ERC20 (ISecurityTokenRegistry (_securityTokenRegistry).polyAddress ());
8794 tokenDetails = _tokenDetails;
95+ granularity = _granularity;
8896 }
8997
9098 function addModule (
@@ -206,6 +214,15 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
206214 emit LogModuleBudgetChanged (_moduleType, modules[_moduleType][_moduleIndex].moduleAddress, _budget);
207215 }
208216
217+ /**
218+ * @dev allows owner to change token granularity
219+ */
220+ function changeGranularity (uint256 _granularity ) public onlyOwner {
221+ require (_granularity != 0 , "Granularity can not be 0 " );
222+ emit LogGranularityChanged (granularity, _granularity);
223+ granularity = _granularity;
224+ }
225+
209226 /**
210227 * @dev Overloaded version of the transfer function
211228 */
@@ -224,7 +241,7 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
224241
225242 // Permissions this to a TransferManager module, which has a key of 2
226243 // If no TransferManager return true
227- function verifyTransfer (address _from , address _to , uint256 _amount ) public view returns (bool success ) {
244+ function verifyTransfer (address _from , address _to , uint256 _amount ) public view checkGranularity (_amount) returns (bool success ) {
228245 if (modules[TRANSFERMANAGER_KEY].length == 0 ) {
229246 return true ;
230247 }
@@ -240,7 +257,7 @@ contract SecurityToken is ISecurityToken, StandardToken, DetailedERC20 {
240257 * @dev mints new tokens and assigns them to the target _investor.
241258 * Can only be called by the STO attached to the token (Or by the ST owner if there's no STO attached yet)
242259 */
243- function mint (address _investor , uint256 _amount ) public onlyModule (STO_KEY, true ) returns (bool success ) {
260+ function mint (address _investor , uint256 _amount ) public onlyModule (STO_KEY, true ) checkGranularity (_amount) returns (bool success ) {
244261 require (verifyTransfer (address (0 ), _investor, _amount), "Transfer is not valid " );
245262 totalSupply_ = totalSupply_.add (_amount);
246263 balances[_investor] = balances[_investor].add (_amount);
0 commit comments