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

SMR-1834-WETH-Bridging #12

Merged
merged 17 commits into from
Oct 26, 2023
Prev Previous commit
Next Next commit
updated comment, reordered functions
  • Loading branch information
proletesseract committed Oct 25, 2023
commit 11aa4ba96812216eafec8dd5dd80142a095d75b1
53 changes: 27 additions & 26 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract RootERC20Bridge is
* @param newChildBridgeAdaptor Address of child bridge adaptor to communicate with.
* @param newChildTokenTemplate Address of child token template to clone.
* @param newRootIMXToken Address of ERC20 IMX on the root chain.
* @param newRootWETHToken Address of ERC20 IMX on the root chain.
* @param newRootWETHToken Address of ERC20 WETH on the root chain.
* @dev Can only be called once.
*/
function initialize(
Expand Down Expand Up @@ -89,6 +89,13 @@ contract RootERC20Bridge is
childBridgeAdaptor = Strings.toHexString(newChildBridgeAdaptor);
}

function updateRootBridgeAdaptor(address newRootBridgeAdaptor) external onlyOwner {
if (newRootBridgeAdaptor == address(0)) {
revert ZeroAddress();
}
rootBridgeAdaptor = IRootERC20BridgeAdaptor(newRootBridgeAdaptor);
}

/**
* @inheritdoc IRootERC20Bridge
* @dev TODO when this becomes part of the deposit flow on a token's first bridge, this logic will need to be mostly moved into an internal function.
Expand All @@ -108,6 +115,25 @@ contract RootERC20Bridge is
_depositETH(receiver, amount);
}

/**
* @inheritdoc IRootERC20Bridge
*/
function deposit(IERC20Metadata rootToken, uint256 amount) external payable override {
_depositToken(rootToken, msg.sender, amount);
}

/**
* @inheritdoc IRootERC20Bridge
*/
function depositTo(IERC20Metadata rootToken, address receiver, uint256 amount) external payable override {
_depositToken(rootToken, receiver, amount);
}

/**
* @dev method to receive the ETH back from the WETH contract when it is unwrapped
*/
receive() external payable {}

function _depositUnwrappedETH(address receiver, uint256 amount) private {
proletesseract marked this conversation as resolved.
Show resolved Hide resolved
_deposit(IERC20Metadata(NATIVE_ETH), receiver, amount, msg.value);
}
Expand Down Expand Up @@ -141,20 +167,6 @@ contract RootERC20Bridge is
}
}

/**
* @inheritdoc IRootERC20Bridge
*/
function deposit(IERC20Metadata rootToken, uint256 amount) external payable override {
_depositToken(rootToken, msg.sender, amount);
}

/**
* @inheritdoc IRootERC20Bridge
*/
function depositTo(IERC20Metadata rootToken, address receiver, uint256 amount) external payable override {
_depositToken(rootToken, receiver, amount);
}

function _depositToken(IERC20Metadata rootToken, address receiver, uint256 amount) private {
if (address(rootToken) == rootWETHToken) {
_unwrapWETH(amount);
Expand Down Expand Up @@ -251,15 +263,4 @@ contract RootERC20Bridge is
}
}

function updateRootBridgeAdaptor(address newRootBridgeAdaptor) external onlyOwner {
if (newRootBridgeAdaptor == address(0)) {
revert ZeroAddress();
}
rootBridgeAdaptor = IRootERC20BridgeAdaptor(newRootBridgeAdaptor);
}

/**
* @dev method to receive the ETH back from the WETH contract when it is unwrapped
*/
receive() external payable {}
}