Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved adjust total supply checkpoints inside of create checkpoint #520 #523

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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