Skip to content

Commit

Permalink
Merge pull request #523 from dev1644/moved-_adjustTotalSupplyCheckpoi…
Browse files Browse the repository at this point in the history
…nts-inside-of-createCheckpoint-#520

Moved adjust total supply checkpoints inside of create checkpoint #520
  • Loading branch information
pabloruiz55 authored Jan 16, 2019
2 parents 49f6a10 + d3ebb61 commit c339f52
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions contracts/tokens/SecurityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
// Map each investor to a series of checkpoints
mapping(address => TokenLib.Checkpoint[]) checkpointBalances;

// List of checkpoints that relate to total supply
TokenLib.Checkpoint[] checkpointTotalSupply;
// Mapping of checkpoints that relate to total supply
mapping (uint256 => uint256) checkpointTotalSupply;

// Times at which each checkpoint was created
uint256[] checkpointTimes;
Expand Down Expand Up @@ -458,13 +458,6 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
emit FreezeTransfers(false, now);
}

/**
* @notice Internal - adjusts totalSupply at checkpoint after minting or burning tokens
*/
function _adjustTotalSupplyCheckpoints() internal {
TokenLib.adjustCheckpoints(checkpointTotalSupply, totalSupply(), currentCheckpointId);
}

/**
* @notice Internal - adjusts token holder balance at checkpoint after a token transfer
* @param _investor address of the token holder affected
Expand Down Expand Up @@ -648,7 +641,6 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
returns(bool success)
{
require(_updateTransfer(address(0), _investor, _value, _data), "Transfer invalid");
_adjustTotalSupplyCheckpoints();
_mint(_investor, _value);
emit Minted(_investor, _value);
return true;
Expand Down Expand Up @@ -692,7 +684,6 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater

function _checkAndBurn(address _from, uint256 _value, bytes memory _data) internal returns(bool) {
bool verified = _updateTransfer(_from, address(0), _value, _data);
_adjustTotalSupplyCheckpoints();
_burn(_from, _value);
emit Burnt(_from, _value);
return verified;
Expand All @@ -709,7 +700,6 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater

function _checkAndBurnFrom(address _from, uint256 _value, bytes memory _data) internal returns(bool) {
bool verified = _updateTransfer(_from, address(0), _value, _data);
_adjustTotalSupplyCheckpoints();
_burnFrom(_from, _value);
emit Burnt(_from, _value);
return verified;
Expand All @@ -735,6 +725,7 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
/*solium-disable-next-line security/no-block-members*/
checkpointTimes.push(now);
/*solium-disable-next-line security/no-block-members*/
checkpointTotalSupply[currentCheckpointId] = totalSupply();
emit CheckpointCreated(currentCheckpointId, now);
return currentCheckpointId;
}
Expand All @@ -754,7 +745,7 @@ contract SecurityToken is ERC20, ERC20Detailed, ReentrancyGuard, RegistryUpdater
*/
function totalSupplyAt(uint256 _checkpointId) external view returns(uint256) {
require(_checkpointId <= currentCheckpointId);
return TokenLib.getValueAt(checkpointTotalSupply, _checkpointId, totalSupply());
return checkpointTotalSupply[_checkpointId];
}

/**
Expand Down

0 comments on commit c339f52

Please sign in to comment.