11pragma solidity ^ 0.5.0 ;
22
33import "../interfaces/IPoly.sol " ;
4+ import "../interfaces/IDataStore.sol " ;
45import "../tokens/SecurityTokenStorage.sol " ;
56import "../interfaces/ITransferManager.sol " ;
67import "openzeppelin-solidity/contracts/math/SafeMath.sol " ;
@@ -10,6 +11,9 @@ library TokenLib {
1011
1112 using SafeMath for uint256 ;
1213
14+ bytes32 internal constant WHITELIST = "WHITELIST " ;
15+ bytes32 internal constant INVESTORSKEY = 0xdf3a8dd24acdd05addfc6aeffef7574d2de3f844535ec91e8e0f3e45dba96731 ; //keccak256(abi.encodePacked("INVESTORS"))
16+
1317 // Emit when Module is archived from the SecurityToken
1418 event ModuleArchived (uint8 [] _types , address _module );
1519 // Emit when Module is unarchived from the SecurityToken
@@ -194,40 +198,45 @@ library TokenLib {
194198
195199 /**
196200 * @notice Keeps track of the number of non-zero token holders
197- * @param _investorData Date releated to investor metrics
201+ * @param _holderCount Number of current token holders
198202 * @param _from Sender of transfer
199203 * @param _to Receiver of transfer
200204 * @param _value Value of transfer
201205 * @param _balanceTo Balance of the _to address
202206 * @param _balanceFrom Balance of the _from address
207+ * @param _dataStore address of data store
203208 */
204209 function adjustInvestorCount (
205- SecurityTokenStorage.InvestorDataStorage storage _investorData ,
210+ uint256 _holderCount ,
206211 address _from ,
207212 address _to ,
208213 uint256 _value ,
209214 uint256 _balanceTo ,
210- uint256 _balanceFrom
215+ uint256 _balanceFrom ,
216+ address _dataStore
211217 )
212218 public
219+ returns (uint256 )
213220 {
214221 if ((_value == 0 ) || (_from == _to)) {
215- return ;
222+ return _holderCount ;
216223 }
217224 // Check whether receiver is a new token holder
218225 if ((_balanceTo == 0 ) && (_to != address (0 ))) {
219- _investorData.investorCount = (_investorData.investorCount).add (1 );
226+ _holderCount = _holderCount.add (1 );
227+ IDataStore dataStore = IDataStore (_dataStore);
228+ if (! _isExistingInvestor (_to, dataStore)) {
229+ dataStore.insertAddress (INVESTORSKEY, _to);
230+ //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
231+ dataStore.setUint256 (_getKey (WHITELIST, _to), uint256 (1 ));
232+ }
220233 }
221234 // Check whether sender is moving all of their tokens
222235 if (_value == _balanceFrom) {
223- _investorData.investorCount = (_investorData.investorCount).sub (1 );
224- }
225- //Also adjust investor list
226- if (! _investorData.investorListed[_to] && (_to != address (0 ))) {
227- _investorData.investors.push (_to);
228- _investorData.investorListed[_to] = true ;
236+ _holderCount = _holderCount.sub (1 );
229237 }
230238
239+ return _holderCount;
231240 }
232241
233242 /**
@@ -284,4 +293,13 @@ library TokenLib {
284293 return (false , bytes32 (hex "54 " ));
285294 }
286295
296+ function _getKey (bytes32 _key1 , address _key2 ) internal pure returns (bytes32 ) {
297+ return bytes32 (keccak256 (abi.encodePacked (_key1, _key2)));
298+ }
299+
300+ function _isExistingInvestor (address _investor , IDataStore dataStore ) internal view returns (bool ) {
301+ uint256 data = dataStore.getUint256 (_getKey (WHITELIST, _investor));
302+ //extracts `added` from packed `whitelistData`
303+ return uint8 (data) == 0 ? false : true ;
304+ }
287305}
0 commit comments