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

Remove half duplex erc20 token support #457

Merged
merged 1 commit into from Jul 29, 2020

Conversation

patitonar
Copy link
Contributor

Closes #405

@patitonar patitonar requested a review from akolotov July 28, 2020 17:01
@patitonar patitonar self-assigned this Jul 28, 2020
}

function setMinHDTokenBalance(uint256 _minBalance) external onlyOwner {
uintStorage[MIN_HDTOKEN_BALANCE] = _minBalance;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also suggest a method to clean up all storage data used by the previous version of contracts as so if we upgrade the bridge tokens contract in the future we can invoke this method to free storage slots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All related contract addresses (Sai, SaiTop, MigrationContract) were hardcoded in the code, so there is only a few storage data to clean. The following method could be called when upgrading the contract version:

function cleanHalfDuplexStorage(address _receiver) external {
    require(msg.sender == address(this));

    delete uintStorage[0x48649cf195feb695632309f41e61252b09f537943654bde13eb7bb1bca06964e]; // keccak256(abi.encodePacked("minHDTokenBalance"))
    delete boolStorage[0xbeb8b2ece34b32b36c9cc00744143b61b2c23f93adcc3ce78d38937229423051]; // keccak256(abi.encodePacked("lockedSaiFixed"))
}

Given that in this case the method only frees up storage I didn't include a flag to allow only one execution by the contract in order to make the returned gas worth. But if you think we should include it anyway here is another version:

function cleanHalfDuplexStorage(address _receiver) external {
    require(msg.sender == address(this));
    bytes32 HALF_DUPLEX_CLEANED = 0xae6828552b008f109b269417f4452957f57fdccaa12685e65c4dd6519defe0a5; // keccak256(abi.encodePacked("halfDuplexCleaned"))
    require(!boolStorage[HALF_DUPLEX_CLEANED]);
    boolStorage[HALF_DUPLEX_CLEANED] = true;

    delete uintStorage[0x48649cf195feb695632309f41e61252b09f537943654bde13eb7bb1bca06964e]; // keccak256(abi.encodePacked("minHDTokenBalance"))
    delete boolStorage[0xbeb8b2ece34b32b36c9cc00744143b61b2c23f93adcc3ce78d38937229423051]; // keccak256(abi.encodePacked("lockedSaiFixed"))
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! It is enough so far.

@akolotov akolotov merged commit dd46135 into develop Jul 29, 2020
@akolotov akolotov deleted the 405-remove-half-duplex-token branch July 29, 2020 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants