Skip to content

Commit

Permalink
Add migration contract (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ducthotran2010 authored May 15, 2022
1 parent 6cd7240 commit 65dfbe0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
15 changes: 15 additions & 0 deletions contracts/v0.5/chain/sidechain/SidechainGatewayMigration.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.17;

import "../../references/ERC20/IERC20.sol";
import "./SidechainGatewayStorage.sol";

contract SidechainGatewayMigration is SidechainGatewayStorage {
function migrateTo(address[] calldata _tokens, address _to) external onlyAdmin {
IERC20 _token;
for (uint256 _i; _i < _tokens.length; _i++) {
_token = IERC20(_tokens[_i]);
_token.transfer(_to, _token.balanceOf(address(this)));
}
}
}
77 changes: 77 additions & 0 deletions contracts/v0.8/migration/BridgeMigration.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IGateway {
function paused() external returns (bool);

function pause() external;

function unpause() external;

function withdrawTokenFor(
uint256 _withdrawalId,
address _user,
address _token,
uint256 _amount,
bytes memory _signatures
) external;
}

interface IGatewayV2 {
function receiveEther() external payable;
}

contract BridgeMigration is Ownable {
IGateway public gateway;
address public weth;

constructor(IGateway _gateway, address _weth) {
gateway = _gateway;
weth = _weth;
}

fallback() external payable {}

receive() external payable {}

function pauseGateway() external onlyOwner {
gateway.pause();
}

function unpauseGateway() external onlyOwner {
gateway.unpause();
}

function migrateAndTransfer(
uint256[] calldata _withdrawalIds,
address[] calldata _tokens,
uint256[] calldata _amounts,
bytes[] calldata _signatures,
IGatewayV2 _gatewayV2
) external onlyOwner {
require(
_withdrawalIds.length > 0 &&
_withdrawalIds.length == _tokens.length &&
_withdrawalIds.length == _amounts.length &&
_withdrawalIds.length == _signatures.length,
"BridgeMigration: invalid array length"
);

gateway.unpause();
for (uint256 _i; _i < _withdrawalIds.length; _i++) {
gateway.withdrawTokenFor(_withdrawalIds[_i], msg.sender, _tokens[_i], _amounts[_i], _signatures[_i]);
}
gateway.pause();

for (uint256 _i; _i < _tokens.length; _i++) {
if (_tokens[_i] == weth) {
_gatewayV2.receiveEther{ value: _amounts[_i] }();
} else {
IERC20(_tokens[_i]).transfer(address(_gatewayV2), _amounts[_i]);
}
}
}
}

0 comments on commit 65dfbe0

Please sign in to comment.