-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ronin-chain/fix/handle-deposit-weth
fix(MainchainGateway): handle deposit weth
- Loading branch information
Showing
13 changed files
with
173 additions
and
45 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -139,4 +139,4 @@ contract BridgeMigration is BaseMigration { | |
} | ||
} | ||
} | ||
} | ||
} |
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
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,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import { WethUnwrapper } from "@ronin/contracts/extensions/WethUnwrapper.sol"; | ||
import { Contract } from "../utils/Contract.sol"; | ||
import { ISharedArgument } from "../interfaces/ISharedArgument.sol"; | ||
import { Migration } from "../Migration.s.sol"; | ||
|
||
contract MainchainWethUnwrapperDeploy is Migration { | ||
function _defaultArguments() internal virtual override returns (bytes memory args) { | ||
ISharedArgument.WethUnwrapperParam memory param = config.sharedArguments().mainchainWethUnwrapper; | ||
|
||
args = abi.encode(param.weth); | ||
} | ||
|
||
function run() public virtual returns (WethUnwrapper) { | ||
return WethUnwrapper(_deployImmutable(Contract.MainchainWethUnwrapper.key())); | ||
} | ||
|
||
function runWithArgs(bytes memory args) public virtual returns (WethUnwrapper) { | ||
return WethUnwrapper(_deployImmutable(Contract.MainchainWethUnwrapper.key(), args)); | ||
} | ||
} |
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
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
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,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
import "../interfaces/IWETH.sol"; | ||
|
||
contract WethUnwrapper is ReentrancyGuard { | ||
IWETH public immutable weth; | ||
|
||
error ErrCannotTransferFrom(); | ||
error ErrNotWrappedContract(); | ||
error ErrExternalCallFailed(address sender, bytes4 sig); | ||
|
||
constructor(address weth_) { | ||
if (address(weth_).code.length == 0) revert ErrNotWrappedContract(); | ||
weth = IWETH(weth_); | ||
} | ||
|
||
fallback() external payable { | ||
_fallback(); | ||
} | ||
|
||
receive() external payable { | ||
_fallback(); | ||
} | ||
|
||
function unwrap(uint256 amount) external nonReentrant { | ||
_deductWrappedAndWithdraw(amount); | ||
_sendNativeTo(payable(msg.sender), amount); | ||
} | ||
|
||
function unwrapTo(uint256 amount, address payable to) external nonReentrant { | ||
_deductWrappedAndWithdraw(amount); | ||
_sendNativeTo(payable(to), amount); | ||
} | ||
|
||
function _deductWrappedAndWithdraw(uint256 amount) internal { | ||
(bool success,) = address(weth).call(abi.encodeCall(IWETH.transferFrom, (msg.sender, address(this), amount))); | ||
if (!success) revert ErrCannotTransferFrom(); | ||
|
||
weth.withdraw(amount); | ||
} | ||
|
||
function _sendNativeTo(address payable to, uint256 val) internal { | ||
(bool success,) = to.call{ value: val }(""); | ||
if (!success) { | ||
revert ErrExternalCallFailed(to, msg.sig); | ||
} | ||
} | ||
|
||
function _fallback() internal view { | ||
if (msg.sender != address(weth)) revert ErrNotWrappedContract(); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.