Skip to content

Commit

Permalink
Try catch to revert with custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Dec 11, 2023
1 parent 1e81ee7 commit bcbb845
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/child/ChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@ contract ChildERC20Bridge is
* @notice Private function to handle withdrawal of L1 native ETH.
*/
function _withdrawETH(uint256 amount) private returns (address) {
if (!IChildERC20(childETHToken).burn(msg.sender, amount)) {
try IChildERC20(childETHToken).burn(msg.sender, amount) returns (bool success) {
if (!success) revert BurnFailed();
} catch {
revert BurnFailed();
}

return NATIVE_ETH;
}

Expand All @@ -330,7 +333,9 @@ contract ChildERC20Bridge is
IWIMX wIMX = IWIMX(wIMXToken);

// Transfer to contract
if (!wIMX.transferFrom(msg.sender, address(this), amount)) {
try wIMX.transferFrom(msg.sender, address(this), amount) returns (bool success) {
if (!success) revert TransferWIMXFailed();
} catch {
revert TransferWIMXFailed();
}

Expand Down Expand Up @@ -372,7 +377,9 @@ contract ChildERC20Bridge is
}

// Burn tokens
if (!IChildERC20(childToken).burn(msg.sender, amount)) {
try IChildERC20(childToken).burn(msg.sender, amount) returns (bool success) {
if (!success) revert BurnFailed();
} catch {
revert BurnFailed();
}

Expand Down Expand Up @@ -486,7 +493,9 @@ contract ChildERC20Bridge is
revert EmptyTokenContract();
}

if (!IChildERC20(childToken).mint(receiver, amount)) {
try IChildERC20(childToken).mint(receiver, amount) returns (bool success) {
if (!success) revert MintFailed();
} catch {
revert MintFailed();
}

Expand Down

0 comments on commit bcbb845

Please sign in to comment.