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

swapping to MCD token on xDai bridge #310

Closed
akolotov opened this issue Oct 30, 2019 · 0 comments · Fixed by #315
Closed

swapping to MCD token on xDai bridge #310

akolotov opened this issue Oct 30, 2019 · 0 comments · Fixed by #315
Assignees

Comments

@akolotov
Copy link
Collaborator

As per the documentation clarifying migration to MCD provided by MakerDAO, the accounts owning SCD must perform two consequent actions:

  • call approve() on the SCD token with the parameters <migration contract address>, <SCD token contract address>.balanceOf(this) (or curBalance)
  • call swapSaiToDai() on the migration contract with the parameter curBalance.

Although these actions could lead to the bridge balance evolution:

  • -curBalance of SCD
  • +curBalance of MCD
    it is not enough for the bridge migration to MCD.

It is necessary also to change the token address in the bridge contract on the Ethereum Mainnet side as so the correct contract was used to unlock tokens when a withdrawal happens. It can be achieved by invoking setErc20token() on the bridge contract. This method is not available for external calls. So, the changing the token address must be performed from a method belonging to the bridge contract.

Bearing in mind facts considered above, the bridge implementation contract must be changed to have a new method migrateToMCD. This method must be permissible to be invoked by the bridge administrators. The method must forbid multiple invocation:

function migrateToMCD(address _migrationContract, address _mcdContract) external onlyOwner {
    bytes32 storageAddress = keccak256(abi.encodePacked("migrationToMcdCompleted"));
    
    require(!boolStorage[storageAddress]);
    require(AddressUtils.isContract(_migrationContract));
    require(AddressUtils.isContract(_mcdContract));

    uint256 curBalance = erc20token().balanceOf(address(this));
    require(erc20token().approve(_migrationContract, curBalance));
    //It is important to note that this action will cause appearing of `Transfer`
    //event as part of the tokens minting
    ScdMcdMigration(_migrationContract).swapSaiToDai(curBalance);
    address saiContract = erc20token();
    setErc20token(_mcdContract);
    require(erc20token().balanceOf(address(this)) == curBalance);

    emit TokensSwapped(saiContract, erc20token(), curBalance);
    boolStorage[storageAddress] = true;
}

The bridge contract on the xDai chain side has no reference to the token contract so no changes is needed on this side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

2 participants