-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cd7240
commit 65dfbe0
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
contracts/v0.5/chain/sidechain/SidechainGatewayMigration.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
} | ||
} |