Skip to content

Commit

Permalink
contracts: replace transferFrom to SafeERC20.safeTransferFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanzhentan committed Dec 1, 2023
1 parent 5b25195 commit 999b872
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contracts/src/L2StandardBridgeBot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity 0.8.20;

import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol";
import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

// See also https://github.com/bnb-chain/opbnb/blob/9505ae88d0ec8f593ee036284c9a13672526a232/packages/contracts-bedrock/contracts/L2/L2StandardBridge.sol#L20
interface IL2StandardBridge {
Expand All @@ -15,6 +16,8 @@ interface IL2StandardBridge {
}

contract L2StandardBridgeBot is Ownable {
using SafeERC20 for IERC20;

address public constant L2_STANDARD_BRIDGE_ADDRESS = 0x4200000000000000000000000000000000000010;
IL2StandardBridge public L2_STANDARD_BRIDGE = IL2StandardBridge(payable(L2_STANDARD_BRIDGE_ADDRESS));

Expand Down Expand Up @@ -46,8 +49,7 @@ contract L2StandardBridgeBot is Ownable {
IERC20 l2Token = IERC20(_l2Token);
bool approveSuccess = l2Token.approve(L2_STANDARD_BRIDGE_ADDRESS, _amount + l2Token.allowance(address(this), L2_STANDARD_BRIDGE_ADDRESS));
require(approveSuccess, "BEP20 withdrawal: approve failed");
bool transferSuccess = l2Token.transferFrom(msg.sender, address(this), _amount);
require(transferSuccess, "BEP20 withdrawal: transferFrom failed");
l2Token.safeTransferFrom(msg.sender, address(this), _amount);

L2_STANDARD_BRIDGE.withdrawTo{value: 0}(_l2Token, _to, _amount, _minGasLimit, _extraData);
}
Expand Down

0 comments on commit 999b872

Please sign in to comment.