-
Notifications
You must be signed in to change notification settings - Fork 11
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
318b4ba
commit dd6ccdd
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
contracts/parent-chain/contract-upgrades/NitroContracts2Point1Point2UpgradeAction.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,60 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.16; | ||
|
||
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; | ||
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
interface IERC20Bridge { | ||
function nativeToken() external view returns (address); | ||
} | ||
|
||
interface IERC20Bridge_v2 { | ||
function nativeTokenDecimals() external view returns (uint8); | ||
} | ||
|
||
interface IERC20Bridge_v2_patch { | ||
function forceEighteenDecimalsPatch() external; | ||
} | ||
|
||
/** | ||
* @title DeployNitroContracts2Point1Point2UpgradeActionScript | ||
* @notice Force the ERC20Bridge contract to set nativeTokenDecimals to 18. | ||
* Will revert if the bridge is not an ERC20Bridge. | ||
* Will revert if ERC20Bridge is not v1.x.x | ||
*/ | ||
contract NitroContracts2Point1Point2UpgradeAction { | ||
address public immutable newBridgeImpl; | ||
|
||
constructor(address _newBridgeImpl) { | ||
require( | ||
Address.isContract(_newBridgeImpl), | ||
"NitroContracts2Point1Point2UpgradeAction: _newBridgeImpl is not a contract" | ||
); | ||
|
||
newBridgeImpl = _newBridgeImpl; | ||
} | ||
|
||
function perform(address bridge, ProxyAdmin proxyAdmin) external { | ||
// ensure the bridge is an ERC20Bridge | ||
try IERC20Bridge(bridge).nativeToken() returns (address) {} | ||
catch { | ||
revert("NitroContracts2Point1Point2UpgradeAction: bridge is not an ERC20Bridge"); | ||
} | ||
|
||
// ensure the bridge is v1.x.x | ||
try IERC20Bridge_v2(address(bridge)).nativeTokenDecimals() returns (uint8) { | ||
revert("NitroContracts2Point1Point2UpgradeAction: bridge is not v1.x.x"); | ||
} catch {} | ||
|
||
// upgrade to the new implementation and call forceEighteenDecimalsPatch | ||
proxyAdmin.upgradeAndCall( | ||
TransparentUpgradeableProxy(payable((bridge))), | ||
newBridgeImpl, | ||
abi.encodeCall(IERC20Bridge_v2_patch.forceEighteenDecimalsPatch, ()) | ||
); | ||
|
||
// ensure decimals were set to 18 | ||
require(IERC20Bridge_v2((bridge)).nativeTokenDecimals() == 18, "decimals not set to 18"); | ||
} | ||
} |